Dominic Charley-Roy
https://github.com/dominiccharleyroy
dominic.charley-roy @ mail.mcgill

git init
git clone
git add/rm
git status
git commit
git log
git diff
git tag
If we work this way, our history will be simple and linear.




git branch BRANCHNAME

git checkout devgit checkout BRANCHNAME
git push -u origin mastergit push -u origin BRANCHNAME
git checkout master
git merge dev


git checkout master # Step 1
git merge dev # Step 2Step 1
Step 2
Initial State
When you're done with a branch, you can delete it:
git branch -d BRANCHNAMEBranches introduce two different ways of collaborating on a project with multiple users.
Suppose we rebase dev onto master to make sure we are up to date. Notice how the commits get copied and we now have linear history (except dev and master are at different points)


Before rebase
After rebase
Note that the red arrows are not history, I just added them to make it clear that the commits were copied.
Suppose you have changes in dev and want to cleanly rebase them into master.
git checkout dev # Switch to dev branch
git rebase master # Perform the rebase
git checkout master # Switch to master
git merge dev # Bring master HEAD up to date with rebased commitsgit rebase -i BRANCH-TO-REBASE-INTORebase -i essentially lets you build the rebasing script. The list of commits to rebase are presented in reverse order.
pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Once that is done, we need to tell rebase to continue:
git commit --amendgit rebase --continueSuppose you rebase and both master and dev have changed the file hello.txt. When you rebase, you will get this error:
If you run git status, you will see what file had a conflict:
error: could not apply ...
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both added: hello.txt
If you open hello.txt, you can see the conflict:
Once you have fixed the conflict (e.g. by only keeping the "Hello from test!" line), we need to stage our fix
And finally, we tell rebase to continue!
<<<<<<< HEAD
Hello, from master!
=======
Hello from test!
>>>>>>> 1f028f3... Updated hello.txt (test)git add hello.txt git rebase --continue
git rebase --abortgit rebase --skipTo stash your working directory, simply do:
When you're ready to work on your changes again:
git stashgit stash applyYou can have more than one stash! To view all of them:
By default, apply uses the most recent stash. To apply a particular stash:
$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
git stash apply stash@{2}Play around with this demo! It's super useful!