How to Upload Directory to Github From Linux
The Git distributed revision control organization is a sweet stride up from Subversion, CVS, Mercurial, and all those others we've tried and fabricated do with. Information technology's great for distributed evolution, when you have multiple contributors working on the aforementioned project, and it is first-class for safely trying out all kinds of crazy changes. Nosotros're going to use a free Github account for practise so we tin can jump right in and start doing stuff.
Conceptually Git is different from other revision control systems. Older RCS tracked changes to files, which you can see when you poke around in their configuration files. Git's approach is more than like filesystem snapshots, where each commit or saved country is a complete snapshot rather than a file full of diffs. Git is space-efficient because it stores only changes in each snapshot, and links to unchanged files. All changes are checksummed, so you are assured of data integrity, and ever existence able to opposite changes.
Git is very fast, because your work is all done on your local PC and then pushed to a remote repository. This makes everything y'all do totally safety, because nothing affects the remote repo until you push changes to it. And even and then you have i more than failsafe: branches. Git'south branching system is bright. Create a branch from your main co-operative, perform all manner of awful experiments, and then nuke it or push it upstream. When it's upstream other contributors can piece of work on it, or you can create a pull request to accept it reviewed, and so subsequently it passes muster merge it into the master branch.
So what if, after all this circumspection, information technology still blows up the main co-operative? No worries, because yous can revert your merge.
Exercise on Github
The quickest way to become some good hands-on Git practise is past opening a free Github account. Figure 1 shows my Github testbed, namedplayground. New Github accounts come with a prefab repo populated past a README file, license, and buttons for quickly creating bug reports, pull requests, Wikis, and other useful features.
Free Github accounts only permit public repositories. This allows anyone to meet and download your files. Still, no i can make commits unless they have a Github account and yous have approved them as a collaborator. If you lot want a private repo hidden from the world you need a paid membership. Seven bucks a month gives you five private repos, and unlimited public repos with unlimited contributors.
Github kindly provides copy-and-paste URLs for cloning repositories. And so you can create a directory on your reckoner for your repository, and and then clone into it:
$ mkdir git-repos $ cd git-repos $ git clone https://github.com/AlracWebmaven/playground.git Cloning into 'playground'... remote: Counting objects: iv, washed. remote: Compressing objects: 100% (four/4), done. remote: Total four (delta 0), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. Checking connectivity... done. $ ls playground/ LICENSE README.dr.
All the files are copied to your figurer, and you lot can read, edit, and delete them but similar any other file. Permit's improve README.medico and learn the wonderfulness of Git branching.
Branching
Git branches are gloriously excellent for safely making and testing changes. You lot can create and destroy them all you want. Let'south make 1 for editing README.md:
$ cd playground $ git checkout -b test Switched to a new co-operative 'exam'
Rungit status
to run across where you lot are:
$ git condition On branch exam nothing to commit, working directory clean
What branches accept you created?
$ git branch * test master
The asterisk indicates which branch you are on.master
is your main branch, the one yous never want to brand any changes to until they take been tested in a branch. Now make some changes to README.dr., and so bank check your status again:
$ git status On branch test Changes non staged for commit: (employ "git add together ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: README.md no changes added to commit (utilize "git add" and/or "git commit -a")
Isn't that nice, Git tells you lot what is going on, and gives hints. To discard your changes, run
$ git checkout README.md
Or you tin delete the whole branch:
$ git checkout master $ git co-operative -D test
Or you tin can accept Git rail the file:
$ git add together README.doctor $ git condition On branch exam Changes to be committed: (apply "git reset Caput ..." to unstage) modified: README.md
At this phase Git is tracking README.md, and information technology is available to all of your branches. Git gives you a helpful hint– if you change your heed and don't want Git to runway this file, rungit reset HEAD README.doc
. This, and all Git activity, is tracked in the.git
directory in your repository. Everything is in plain text files: files, checksums, which user did what, remote and local repos– everything.
What if you have multiple files to add? You can list each one, for casegit add together file1 file2 file2
, or add all files withgit add *
.
When there are deleted files, you tin can utilisegit rm filename
, which only un-stages them from Git and does not delete them from your arrangement. If you accept a lot of deleted files, usegit add -u
.
Committing Files
At present let's commit our changed file. This adds it to our branch and information technology is no longer available to other branches:
$ git commit README.md [exam 5badf67] changes to readme i file changed, 1 insertion(+)
You'll be asked to supply a commit message. It is a skillful practise to make your commit messages detailed and specific, merely for now we're not going to be also fussy. At present your edited file has been committed to the branchexamination
. It has not been merged with master or pushed upstream; it's just sitting there. This is a good stopping point if you need to go do something else.
What if y'all take multiple files to commit? You tin can commit specific files, or all available files:
$ git commit file1 file2 $ git commit -a
How do you know which commits have not yet been pushed upstream, but are still sitting in branches?git condition
won't tell you, and then use this command:
$ git log --branches --not --remotes commit 5badf677c55d0c53ca13d9753344a2a71de03199 Author: Carla Schroder Appointment: Thu November xx 10:19:38 2014 -0800 changes to readme
This lists un-merged commits, and when it returns nothing then all commits have been pushed upstream. At present permit's push this commit upstream:
$ git push origin test Counting objects: 7, done. Delta compression using up to eight threads. Compressing objects: 100% (iii/iii), done. Writing objects: 100% (3/3), 324 bytes | 0 bytes/s, done. Total iii (delta 1), reused 0 (delta 0) To https://github.com/AlracWebmaven/playground.git * [new co-operative] test -> test
You may exist asked for your Github login credentials. Git caches them for 15 minutes, and you can change this. This example sets the enshroud at two hours:
$ git config --global credential.helper 'cache --timeout=7200'
Now get to Github and look at your new branch. Github lists all of your branches, and you can preview your files in the different branches (effigy 2).
Now you can create a pull asking past clicking the Compare & Pull Request button. This gives you some other chance to review your changes before merging with master. Y'all can also generate pull requests from the command line on your computer, simply it's rather a cumbersome process, to the point that you can find all kinds of tools for easing the procedure all over the Web. Then, for at present, we'll use the dainty clicky Github buttons.
Github lets you view your files in plainly text, and it also supports many markup languages so yous can see a generated preview. At this point you can push button more changes in the same co-operative. You can besides make edits directly on Github, just when you lot do this y'all'll get conflicts between the online version and your local version. When you are satisfied with your changes, click the Merge pull request button. Yous'll take to click twice. Github automatically examines your pull request to encounter if it can be merged cleanly, and if at that place are conflicts y'all'll take to fix them.
Another nice Github feature is when you have multiple branches, yous tin can cull which one to merge into by clicking the Edit button at the correct of the branches list (figure iii).
After you have merged, click the Delete Branch button to continue everything tidy. Then on your local computer, delete the co-operative by commencement pulling the changes to master, then y'all tin can delete your branch without Git complaining:
$ git checkout master $ git pull origin primary $ git branch -d exam
You can force-delete a branch with an uppercase-D
:
$ git branch -D test
Reverting Changes
Again, the Github pointy-clicky way is easiest. It shows you a listing of all changes, and you tin revert whatever of them by clicking the appropriate push. You tin even restore deleted branches.
Yous can likewise do all of these tasks exclusively from your command line, which is a great topic for another mean solar day considering it's complex. For an exhaustive Git tutorial endeavour the free Git volume.
Source: https://www.linux.com/training-tutorials/beginning-git-and-github-linux-users/
0 Response to "How to Upload Directory to Github From Linux"
Post a Comment