Monday, 4 June 2012

Advanced git features

Hi everybody,

I am using git as source control for a long time ago, and I am happy with what it offers. I presume that the basic git commands are clear for everyone. So in this post I will write about some more advanced git commands which aren't used so frequently but they are invaluable when they are needed.

-Nice Git log which contains a lot of usefull info:
git log --graph --all --decorate=full --abbrev-commit --pretty=short

-Delete the branch 'staging' on remote 'staging':
git push staging :staging

-push the branch "newfeature" to the remote "origin":
git push origin newfeature

-create a remote branch:
git push  :refs/heads/new_feature_name

-list remote branches:
git branch -r

-diff between two branches:
git diff <branchone>..<another branch>

-create a branch wich tracks a remote branch:
git checkout --track -b <new_feature_name> <origin>/<new_feature_name>

-track a remote branch:
git branch --set-upstream <local_branch> <remote>/<remote_branch>

-push to a remote:
git push <remote> <local branch name>:<remote branch to push into>

-configuring to push automatically to a certain remote branch, without specifying the local branch and the remote branch:
git config remote.<remoteName>.push <localBranchName>:<remoteBranchName>

Enjoy and easy your life :)