Monday, July 9, 2012

Git daily usage cheat sheet


TaskCommand
Initialize a new git repository
git init
View local branchesgit branch
Create new local branchgit branch [new_branch_name]
Delete local branchgit branch -d [branch_name]
Switch to a branchgit checkout [branch_name]
Add files to gitgit add .
Undo all current changes.git checkout .
Commit changesgit commit -a -m "Log message"
Show git logsgit log
Push local to remotegit push origin [branch_name]
Pull from remotegit pull origin [branch_name]
Merge branchgit merge [from_branch]
Show diffgit diff
Show all branchesgit branch -a
Fix a tagged release
git checkout -b [tag_name]_fixes [tag_name]
OR (for getting a remote branch)
git checkout -b [new_local_branch] origin/[remote_branch]

e.g.

git checkout -b myfeature origin/myfeature
Create a new taggit tag [tag_name]
Push tags to remotegit push --tags
Overwrite existing taggit tag -f [tag_name]
Delete tag
git tag -d 12345
git push origin :refs/tags/12345
Merge individual commitsgit cherry-pick [commit_hash]
Stashing
git stash
git stash apply
git stash list
Create an empty repositorygit --bare init
Adding a remote repository
git remote add origin [server_name]:[directory_name]

Checkout a single file on another branch:
$ git checkout branch_name file_full_path

More on: http://gitref.org/index.html