Rob Conery created an excellent Git Cheatsheet as a part of his Mastering Git video series on his training site TekPub. I decided to tweak this cheat sheet (just a touch) with a few handy git commands:
Git Cheatsheet 1.1
Common Commands
git init (creates a new repo in the current directory)
git init --shared --bare - create a repo on a share
Checkin
git add . (add's all unstaged files to staging)
git commit -m "Message" (commits all unstaged files)
Checkin all changes to tracked files
git commit -am "Message"
Mistakes
git checkout -f (undo local changes)
git reset HEAD - points the head to a previous commit, removing all commits inbetween
git revert HEAD - resets the HEAD to the last commit and reverses everything from the
previous commit. It also adds a commit which details the stuff removed, etc.
git reset --hard (in an emergency break glass)
Configuration
git config --global user.name (sets your username)
git config --global user.email (sets your email)
git config --core.editor (sets your preferred text editor. We suggest "write" - notepad)
Branching
git checkout -b branchname (creates a branch and switches to it)
git branch branchname (creates a branch)
git branch -D branchname (deletes a branch)
Viewing History
gitk (brings up the repo viewer for the current branch)
gitk --all (brings up the repo viewer for all branches)
Merge
git mergetool
Diff/Merge tools (add to .gitconfig)
This section assumes p4Merge which you can get from Perforce.com for free. Add your
favorite below as needed, and make sure to order the arguments as needed.
[diff]
external = "c:/users/username/difftool.sh"
[merge]
tool = p4merge
[mergetool "p4merge"]
cmd = "p4merge.exe" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
Difftool.sh
#!/bin/sh
p4merge "$2" "$5"
Standard Git Ignore
*resharper.user
[Dd]ebug/
[Rr]elease/
build/
[Bb]in/
[Oo]bj/
*.suo
*.sln.cache
_ReSharper.*/
AssemblyInfo.cs
Git Hub
git pull origin branchname
git push origin branchname
git clone githubrepourl
No comments:
Post a Comment
Your feedback is appreciated!