GettingStartedWithGit

From GMOD
Jump to: navigation, search

Much of this adapted from http://www.tpope.net/rails-git-best-practices

Installing and Configuring Git

1. Install `git` if you don't already have it. On Debian and Ubuntu, this can be done with:

   sudo apt-get install git-core

2. Configure git to know your name and email:

   git config --global user.name "Robert Buels"
   git config --global user.email "rmb32@cornell.edu"

3. Enable color for many of the git commands:

   git config --global color.diff auto
   git config --global color.status auto
   git config --global color.branch auto
   git config --global color.interactive auto

4. That's all!

Learning to Use Git

To learn how to use `git`, try the links at http://git-scm.com/documentation, especially:

Git Tricks

Tab completion and customized command prompt

Since development using `git` is usually done with lots of branches, it's often very desirable to know what branch you are on at any given time. It's quite nice to be able to tab-complete branch names and so forth.

https://github.com/git/git/raw/master/contrib/completion/git-completion.bash is a `bash` script that enables these features. Get that and put it in someplace like ~/bin/git-completion.bash. Then you can put something like this in your .bashrc to use it:

   #!sh
   # git stuff
   if [ -f ~/bin/git-completion.bash ]; then
      export GIT_PS1_SHOWDIRTYSTATE=1
      export GIT_PS1_SHOWSTASHSTATE=1
      export GIT_PS1_SHOWUNTRACKEDFILES=1
      source ~/bin/git-completion.bash
      export PS1='\u\[\033[00;32m\]@\h\[\033[00m\] \[\033[01;34m\]\W\[\033[00m\]$(__git_ps1 " (\[\033[01;34m\]%s\[\033[00m\]%s\[\033[01;31m\]%s\[\033[00m\]\[\033[01;31m\]%s\[\033[00m\]\[\033[01;31m\]%s\[\033[00m\]\[\033[01;31m\]%s\[\033[00m\]\[\033[01;31m\]%s\[\033[00m\])")\$ '
   fi


It makes your prompt look like this:

  rob@banana sgn (master*%)$


Where 'master' is the branch name, and the '*' appears if you have changed files, and '%' indicates you have untracked files.

It also gives you tab completion of git commands, branch names, and the like. Try typing `git check<tab>` and if you have it set up correctly, you'll see that it completes the command to `git checkout`.