My blog, keeping you up-to-date on my latest news.


Git tricks and tips

Linux • 2013-01-26


I''ve been using git for one year now and I love it. That''s why I''ll share with you two or three tricks and tips about this wonderful tool. For information I use git version

Colors in Git

Git can color its output to your terminal, which can help you visually parse.

$ git config --global color.ui true

Show branches and tags in git log

$ git log --oneline --decorate
293f2f8 (HEAD, origin/master, github/master, master) Refactoring Phpunit
31d665d - Add fields for database - send forgotten password test
2a0b820 Add tempory directory
bf7e810 Admin user can retrieve his password
50e55c6 Updater tests
399b8c1 CS
1228e5f Refactoring updater, execute all scripts from younger version
cb65830 Is Writable refactoring
0687099 Move _copyDirectory and _isWritable into static method in Gc\Media\File
321bcae #14 Sitemap - Don''t generate if has no change
043b2bd CS
5de0924 (tag: v0.1.3) GotCms 0.1.3
04ade43 #14 Sitemap - setBasePath

Show latest commit

Begin with the word "GotCms" in its messages.

$ git show :/^GotCms

The first line of the commit message of all local branches

$ git log --oneline --branches --no-walk

Working with remotes


$ git remote -v
github (fetch)
github (push)
origin  gitolite@x.x.x.x:gotcms (fetch)
origin  gitolite@x.x.x.x:gotcms (push)


$ git remove rm github

Add new

$ git remote add github

And push to infinity and beyond

$ git push -u github master

Play with git tag

Git tag is a great way to denote specific release versions of you projet.

$ git tag -a v1.0.0 -m "Creating the first official version."
$ git show v1.0.0
$ git push origin --tags

Resetting the current branch

If you have committed junk but not pushed.

$ git reset --soft HEAD^

When you want to reset to the current HEAD.

$ git reset --hard HEAD

When a branch tracking a remote has become outdated (e.g. you are on staging now but your commits have diverged)

$ git reset --hard origin/staging



$ git branch dev
$ git checkout dev


$ git checkout master
$ git merge dev # Or...
$ git rebase dev

<< Back to Blog Discuss this post




No comments


Add a comment

  • Please verify you are human