-
Notifications
You must be signed in to change notification settings - Fork 0
- Pro Git
- Great visualization of basic Git commands for moving source around
- A Visual Git Reference
- GitHub's Git Cheat Sheet (PDF)
- A fantastic visual introduction to the high-level concepts around Git and branching. If you are at all interested in using branches, this is one is not to be missed.
- Why is Git so hard? (it's not just you!)
- Try Git
- Learn Git Branching
- Spring 2014 NINJA tutorial: GitHub Help
- Spring 2014 NINJA tutorial: Introduction to Version Control
- Spring 2014 NINJA tutorial: Pushing to your GitHub repository
Git & GitHub presentation (thanks: Chris)
One-page cheat sheet (PDF, thanks: Celine)
$ git add <filename>
$ git commit -m "<commit-message>"
$ git push
You can alternatively use git commit -am '<commit-message>'
to both add all
of the files in your folder and put a message on them, all in one command!
If you forget to include -m
in your commit, git will open a text-editor called
vim so that you can enter a commit message there. To write your commit message
in vim, first press “i”, then write your message, then type :wq for write-
quit. Alternatively, if you just want to escape from vim's interface without
saving a message, just enter “:q” for quit.
$ git pull
-or-
$ git pull origin master
If you get merging errors telling you that you need to merge or 'stash' before you can pull, see the 'stashing' section below. Also, a quick note on pulling, what pulling means is that you're taking the code that others have pushed to your repository and matching what you have on your computer with that, so it incorporates their changes.
$ git stash
Stashing stores the copy of your current version of the repository on your computer, so you can keep that copy there before you pull changes that others have made. Often, you'll be prompted to stash before pulling or merging with others. Now that you've stashed, how do you get your stuff back? You'll probably do the following:
$ git stash
$ git pull
$ git stash pop
Git stash will store your changes locally, git pull will download the changes other have made to the repository, and git stash pop puts the changes that you made locally that conflict directly in the code. If there's anything to merge, do it in the file and then commit and push your changes.
$ git checkout master
If this doesn't work, try:
$ git checkout origin/master
Branches on Git are very similar to branches on trees. The tree trunk is
represented as the master
branch and the branches that come off of the
master branch you can name whatever you want. These branches will start at
whatever state master was at the time you made the branch. The master branch
can continue changing independently of the branch that you created. You can
combine the changes that you make in separate branches by 'merging' them
together. For more on merging, look at the sections that will follow. Also,
you can view all of the branches in your repository by doing:
$ git branch -a
And you can tell what branch you're on by doing the command:
$ git branch
$ git fetch origin
$ git checkout -b <your-branch-name> origin/master
This branch will exist on your computer, in order to push it to git and have it be visible by others, you'll have to push your local branch to be a remote branch (see below)
$ git push -u origin <your-branch-name>
'Checking out' a branch is when you pull another person's branch (or teleport to another branch), you do it by doing:
$ git fetch origin
$ git checkout <branch-name>
See Resolving a Merge Conflict Using the Command Line on GitHub.
Let's say that you've been working on a branch called dev
and you have also
been modifying the master
branch. You want to merge your changes in the
master
branch into the dev
branch, so that your dev
branch is up to
date. What you want to do is first get into the dev
branch, then:
$ git fetch origin
$ git merge origin/master
If you have any conflicts, deal with them, commit and push your changes, and you're good to go!