#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<p></p>
<p>#Setting up git from another repo
git clone < remote_label > < optional_dir_location > #clone a repo with git config ready</p>
<p>#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</p>
<p>#Merging
git checkout < branch to be merge ><br>
git merge < branch_name > #merge recursively and auto commit</p>
<p>additional info - <a href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html" title="git merge">git merge man page</a></p>
<p>#fetch & pulling
git pull < remote_label > < branch_label> #it will recursively merge with your repo
git fetch < remote_label ></p>
<p>#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</p>
<p>#Tagging
git tag -a < comment > #to remember a specific point
git push –tag #pushes tag</p>
<p>#To delete a tag
git tag -d < tag_name >
git push origin :< tag_name ></p>
<p>#if tag name is same as one of your branch name
git tag -d < tag_name >
git push origin :refs/tag/< tag_name ></p>
<p>#Logging
git log #shows the commit log</p>
<p>#Untrack a file
git rm –cache < file_name > #untracks a file, thus not included in repo</p>
<p>#Stashing
git stash</p>
#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<p></p>
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