Skip to content

Bootcamp May 13 Git, get it?

harleyttd edited this page Sep 13, 2010 · 4 revisions

Okay. Git has a steep learning curve, but it’ll be useful later so don’t discard it as not worth learning =) If you are new to Git, please please take some time to read the following =)

So instead of attempting to write tutorials – there are better sources on the internet. I thought it’d be useful to summarize some notes that we come across quite often as new comers.

A lot of us have got stuck with error when pushing.

Remember to always commit or stash your changes before switching branch. Pull before you push. Usually you only have to worry about merge but rebase is another way to deal with overlapping changes – a bit dangerous as it discard existing commit objects. Sometimes you need to manually resolve merging conflicts (more on this later). Read the following very useful short note.

Set up your aliases.

See for example, if you type “gb” for “git branch”, you save 8 key strokes each time you call it. For some of you who played with git yesterday, who used it like 30 times. You don’t need WolframAlpha to know that this can be a huge time saver. At least please at least consider aliases for “git status” and “git branch” because you may use it as often as “ls” in linux (also that’s why unix “ls” is short rather than “list directories”). Here are my suggestions: (put these in either your .bash_profile or .bashrc file in your home folder).


alias gb='git branch'
alias gst='git status'
alias gc='git commit'
alias gl='git pull'
alias gp='git push'
alias gco='git checkout'

Note that you can still add additional arguments, such as “gb -a” or “gc -m” etc.

Do not be afraid of conflicts.

This is a natural thing for collaboration. It could be often avoided if every follows good practice and there’s a clear divide between the work, but for a start, it’s impossible to be conflict free. Please take the time to read this article to understand how to deal with and avoid conflicts.
Some people feel confident with just editing the conflict file directly (remember the <<<<<<, === and >>>>> lines?), but you can also make it easier for yourself by using git-mergetool (when you type in terminal, no need dash). I will demonstrate this tomorrow. For those who are at home reading this, you can just try creating a test folder, git init, checkout a new branch, create a file, checkout another branch, create the same file with a different content, then merge them, then use git mergetool which links to a colorful text editor for you to enjoy resolving conflicts.