Clone remote repository
$ git clone repo_path
Or start a new git repository for an existing code base
$ cd /path/to/project/
$ git init (1)
$ git add . (2)
$ git commit (3)
Add remote repository
$ git remote add origin [:repository_path]
$ git push origin master
Local branch list
$ git branch
Remote branch list
$ git branch -r
Local + remote branch list
$ git branch -a
Show remote origin
$ git remote show origin
Checkout a branch listed in branch list
$ git checkout branch_name
Create new branch
$ git checkout -b [name_of_your_new_branch]
Push branch on remote repo
$ git push origin [name_of_your_new_branch]
Merge a branch to the current checkout branch
$ git merge branch_name
If you want to rename a branch while pointed to any branch
$ git branch -m <oldname> <newname>
If you want to rename the current branch
$ git branch -m <newname>
Push renamed branch to remote repo
$ git push origin :[name_of_your_new_branch]
Add a new remote for local branch
$ git remote add origin [url_of_remote_repository]
Push changes from your commit into your branch
$ git push [name_of_your_new_remote] [name_of_your_branch]
Delete a branch from local filesystem
$ git branch -d [name_of_your_new_branch]
To force the deletion of local branch from filesystem
$ git branch -D [name_of_your_new_branch]
Delete the branch on github
$ git push origin :[name_of_your_new_branch]
Untrack a file
$ git rm --cached project_file_path
Update remote branch list
$ git remote update origin --prune
Change remote repository
$ git remote set-url origin repo_url.git
$ git remote set-url --push origin repo_url.git
Checkout remote branch
git fetch
git checkout [:branch_name]
Fetch remote branches(it will also remove local branches which are remotely deleted)
$ git fetch -p
To fetch a branch, you simply need to
$ git fetch origin
$ git checkout -b branch_name origin/branch_name
Rollback to previous commit
git reset HEAD~1