Monday, October 10, 2011

Git tips!

When you work on a project managed by Git, you have to type a lot to see status and results. For example, to seen which branch you're working on, you have to type:
#git branch
You'll see a list of branches and the one with an asterisk is the current branch you are on at the moment.

If you want to switch to another branch you have to do like:
#git chekout nameofbranch

There are some nice stuff we can do, like showing the current branch in the prompt!
Put the following lines in your .bashrc file:
export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\]\w\[\033[01;33m\]$(__git_ps1)\[\033[01;34m\] \$\[\033[00m\] '


Furthermore, adding .gitconfig file in your home directory will automatically change the behavior of Git. My .gitconfig looks like following:


[user]
name = My Name
email = My.Email@gmail.com


[alias]
ci = commit
co = checkout
st = status
di = diff
br = branch


[pager]
color = true


[color]
ui = true


[core]
editor = vim


[format]
pretty = oneline

Especially those alliases are cool. If I want to checkout to a branch, I can do this:
#git co nameofbranch

No comments:

Post a Comment

NSNotification example