Transcribed from Tower’s blog post
$ git clone ssh://[email protected]/repo.git
Clone an existing repository
$ git init
Create a new local repository
$ git status
Changed files in your working directory
$ git diff
Changes to tracked files
$ git add .
Add all current changes to the next commit
$ git add -p <file>
Add some changes in to the next commit
$ git commit -a
Commit all local changes in tracked files
$ git commit
Commit previously staged changes
$ git commit --amend
Change the last commit Don’t amend published commits!
$ git log
Show all commits, starting with newest
$ git log -p <file>
Show changes over time for a specific file
$ git blame <file>
Who changed what and when in <file>
$ git branch
List all existing branches
$ git checkout <branch>
Switch HEAD branch
$ git branch <new-branch>
Create a new branch based on your current HEAD
$ git checkout --track <remote/branch>
Create a new tracking branch based on a remote branch
$ git branch -d <branch>
Delete a local branch
$ git tag <tag-name>
Mark the current commit with a tag
$ git remote -v
List all currently configured remotes
$ git remote show <remote>
Show information about a remote
$ git remote add <remote> <url>
Add new remote repository, named <remote>
$ git fetch <remote>
Download all changes from <remote>
, but don’t integrate into HEAD
$ git pull <remote> <branch>
Download changes and directly merge/integrate into HEAD
$ git push <remote> <branch>
Publish local changes on a remote
$ git branch -dr <remote/branch>
Delete a branch on the remote
$ git push --tags
Publish your tags
$ git merge <branch>
Merge <branch>
into your current HEAD
$ git rebase <branch>
Rebase your current HEAD onto <branch>
Don’t rebase published commits!
$ git rebase --abort
Abort a rebase
$ git rebase --continue
Continue a rebase after resolving conflicts
$ git mergetool
Use your configured merge tool to solve conflicts
$ git add <resolved-file>
$ git rm <resolved-file>
Use your editor to manually solve conflicts and (after resolving) mark file as resolved
$ git reset --hard HEAD
Discard all local changes in your working directory
$ git checkout HEAD <file>
Discard local changes in a specific file
$ git revert <commit>
Revert a commit (by producing a new commit with contrary changes)
Reset your HEAD
pointer to a previous commit
$ git reset --hard <commit>
...and discard all changes since then
$ git reset <commit>
...and preserve all changes as unstaged changes
$ git reset --keep <commit>
...and preserve uncommitted local changes