git config --systemStored in /etc/gitconfig or Program Files\Git\etcgitconfig
git config --globalStored in ~/.gitconfig or c:\Users<name>.gitconfig
git configStored in .git/config in each repo
git config --global --listgit config --global user.name "UserNameHere"git config --global user.email "[email protected]"git config --global core.editor "vim"git config --global help.autocorrect 1Fixes dodgy typing
git config --global color.ui autogit config --global core.autocrlf input- Windows = true
- Mac / Linux = input
git add -uStage all modified files.
git diff sha..shagit diff HEAD~1..HEAD1 commit back from the head
git diff HEAD~1..1 commit back from the head
git diff --cachedgit add -AAdd all untracking files
git add -UStage all modified files
git commit -am ""adds modified files at the same time
git add <filename>
git commit -m "description"git status will show the file as tracked
git checkout <filename>pulls the file from the HEAD version
git reset --hardReset the working copy back to the head
git reset --soft HEAD~1Reset the working copy back to a sha
git reset --hard HEAD~1Discard the changes made in the commit
Amend the last commit message
git commit --amendgit reset --hard SHATo remove from github
git push [remote] +[branch]git clean -nWhat would I clean?
git clean -fPerform the action
git log --oneline | wc -lHow many commits made?
git log --oneline --graphAdds a graph down the left hand side
git log branchgit shortlog
Lists the authors in the changes and the commit messages
git shortlog -snenumerical order decrease e email address
git show HEADgit show <SHA>git remotegit remote -vverbose
git remote rm <name>git branchgit branch -rshow remote branches
git taggit tag -v <tagname>verify signed tag
You can add a remote branch (mutiple remotes) when someone sends a pull request to examine their changes.
git remote add <origin> <location>git fetchPull down the changes from a remote repo. Does not incorporate changes
git fetch <remote>git pullShort cut for git fetch, git merge
git pull <remotebranch> <localbranch>If tracking has not been set. Cloning does this automatically
git merge <remote>merge changes from remote branch into local branch
git branch --set-upstream master origin/masterFriendly name for a sha1 hash.
git tag <name>unsigned tag
git tag v1.0git tag -a messagewith annotation
git tag -s v1.0Automatically requires a message. Passphrase required for signing key.
Removing a local tag
git tag -d <name>Removing from git hub
git push <remote> :<tagname>By default git does not push tags
git push --tagsBranches are labels on the sha commits
git branch <feature name>git branch <feature name> <sha>git checkout -b <name>Create and switch branch
git branch -d <name>delete branch
git branch -D <name>Force
Commits are around for 30 days by default.
git reflogUse this to locate the sha
git branch <name> shagit config --global alias.lga "log --graph --oneline --all --decorate"Store changes but do not apply.
git stashgit stash listgit stash applygit stash popapply the last stash
git stash dropdrop reference to a stash
git stash branch <x>Create branch from stash, check it out and apply
git merge <branch to pull changes from>git mergetool(don't forget the working copy will contain .orig files, so simply delete them)
Replay changes onto a branch.
go the branch to rebase from:
git rebase <targetbranchname>If you can conficts when merging.
git mergetoolResolve the conflict
git rebase --continueSquash mutiple commits into a single commit
git rebase -igit rebase -i HEAD~n- 1 pick c196b54 Feature8
- 2 squash 7787a9c Feature7
- 3 squash f771621 Master in the house
You must have root commit to go back to.
git cherry-pick <sha>select a single commit and apply it.
git push origin <branchname>Push creating a new remote branch
git push origin <branchname>:<branchname>Create new remote branch from remote branch
git push origin :<branchname>Deletes the remote branch
http://ndpsoftware.com/git-cheatsheet.html