Git Cheat Sheet

Mon Dec 17, 2012   0

#Setting up git from scratch
git init                                             #initialize git
git remote add < remote_label > < destination >      #adds a new remote destination with a label
git fetch < remote_label >                           #fetches the head of the repo
git checkout master                                  #checkouts the master branch

#Setting up git from another repo git clone < remote_label > < optional_dir_location > #clone a repo with git config ready

#Branching git branch #list all branches git branch < branch_label > #creates a new local branch with name < branch_label > git branch -d < branch_label > #deletes the local branch with name < branch_label > git push < remote_label> :< branch_label > #deletes remote branch

#Merging git checkout < branch to be merge >
git merge < branch_name > #merge recursively and auto commit

additional info - git merge man page

#fetch & pulling git pull < remote_label > < branch_label> #it will recursively merge with your repo git fetch < remote_label >

#Commit git commit -a -m < message > #local commit git commit -amend -m < message > #edit last commit message git push < remote_label > < branch_label > #commits to remote branch

#Tagging git tag -a < comment > #to remember a specific point git push –tag #pushes tag

#To delete a tag git tag -d < tag_name > git push origin :< tag_name >

#if tag name is same as one of your branch name git tag -d < tag_name > git push origin :refs/tag/< tag_name >

#Logging git log #shows the commit log

#Untrack a file git rm –cache < file_name > #untracks a file, thus not included in repo

#Stashing git stash

#cloning a bare repo for deployment purpose git clone –bare

additional info git stash man page

#reverting to previous commits  [Advance]
git checkout < commit_hash >                     #checkout the indicated commit hash
git checkout -b < branch_label > < commit_hash>  #branches with < branch_label > and checkout to the commit hash
git reset –hard < commit_hash >                 #destroys the local modification, you will loose the uncommit work
git revert < commit_hash >                       #reverts to the previous commit

additional info - git revert man page & stack over flow git revert qa

#splitting a subpath out into a new repo
git filter-branch –prune-empty –subdirectory-filter lib master

additional info - github:help

comments powered by Disqus