Git Cheat Sheet


Git cheat sheet
Creating & fetching repositories
Create an empty repository
Undo the last commit (if you haven’t pushed it)
Create a branch based upon the current branch
$ mkdir repo && cd repo && git init
$ git reset --soft HEAD^
$ git checkout -b new-branch
Fetch a project by cloning
Revert the last commit (if you have pushed it)
List the commits between master and testing since
the last merge of master into testing
$ git clone user@host:/path/to/repo.git
$ git revert HEAD
$ git log --oneline testing..master
Fetch a project without “clone”
Show commit history
Create a completely empty branch
$ mkdir repo && cd repo && git init
$ git log [path]
# Make sure your tree is clean first!
$ git remote add remote-name user@host:/
Generate a patch for a single commit
$ git symbolic-ref HEAD refs/heads/
$ git format-patch -1 commit-hash
$ git pull remote-name branch-name
Fix a mistake in the log message of your last commit
$ rm .git/index && git clean -fdx
Fetch a branch you don’t already have
$ git commit --amend
$ git commit --allow-empty -m’Initial
$ git fetch remote-name branch-
Apply a patch to the current tree
List local branches
Fetch the latest changes to the current branch
$ git am filename.patch
$ git branch
$ git pull remote-name branch-name
Apply a diff without committing
List remote branches
Pull changes without a configured remote
$ git apply filename.diff
$ git ls-remote --heads remote-name
$ git pull user@host:/path/to/repo branch-
Throw away a branch and start again
Update submodules to the stored commit
$ git checkout other-branch
$ git submodule update --init
$ git branch -D dead-branch
Set your name and e-mail address
Show submodule status
Delete a branch on a remote
$ git config --global ‘John
$ git submodule
$ git push remote-name :branch-name
$ git config --global
Add a submodule
Merge everything from master into testing
$ git submodule add user@host:/repo/.git
$ git checkout testing
Create an alias for a command
# When the merge is complete, master and
# Allow ‘git st’ to be used for ‘git
testing will have converged
$ git merge master
an alias for a URL to a repository
$ git config --global status
somewhere else
Roll forward a branch to incorporate changes made to
Enable a global “ignores” file
its parent
parent commit
the commit which precedes this one
$ git config --global core.excludesfile
$ git checkout feature-branch
parent branch
the branch from which this one diverges
$ git rebase parent-branch
a branch created to keep development of a
feature branch
feature separate
- v2 - 2005-05-12
an alias for the most recent commit on the
current branch


00 votes

Related Articles

Related forms

Related Categories

Parent category: Education