Git Commands


Show branch details

$git branch -v -a

$git branch -a

$git branch -r

$git remote show origin

List revision

$git rev-list -n 2 HEAD -- <file_path>

Retrieve new branch

$git fetch origin

$git fetch origin --prune

Create Branch

$git checkout -b test origin/test

Set upstream

$git branch --set-upstream-to=origin/<BRANCH> <BRANCH>

Push to Origin

$git push -u origin <BRANCH>


$git merge --no-ff <BRANCH>


$git fetch origin

$git reset --hard origin/master


delete local branch:

$git branch -d testing

$git branch -D testing (force)

delete remote:

$git push origin :<BRANCH> or :refs/heads/<BRANCH>


Undelete file

if file was removed without commit.

$git reset <file>


$git checkout <file> ??

Get revision

$git checkout <revision>^ -- <file_path>

Get commit hash


git rev-parse --verify HEAD


git rev-parse --short HEAD

Rebase (update to one commit).

$git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

Merge/cherry pick

$git cherry-pick b50788b

(note: don't forget to do a pull locally from the origin branch)


Create Branch and push to Remote

$git checkout -b test origin/test
$git push -u origin <BRANCH>

Set upstream

$git branch --set-upstream-to=origin/<BRANCH> <BRANCH>

Change remote

git remote rm origin

$ git remote add origin
# Set a new remote

$ git remote -v
# Verify new remote
> origin (fetch)
> origin (push)



Sets the commit's message. Make sure to provide a concise description that helps your teammates (and yourself) understand what happened.


Includes all currently changed files in this commit. Keep in mind, however, that untracked (new) files are not included.


Rewrites the very last commit with any currently staged changes and/or a new commit message. Git will rewrite the last commit and effectively replace it with the amended one. Note that such a rewriting of commits should only be performed on commits that have not been pushed to a remote repository, yet.