Difference between revisions of "Learning more about git"

From Wiki for iCub and Friends
Jump to: navigation, search
(Some Color)
(Bash Prompt)
Line 30: Line 30:
 
Bash prompt can be tweaked to show you in which branch you are by using ''__git_ps1''. For example you can replace your default prompt in your ''~/.bashrc'' file with:
 
Bash prompt can be tweaked to show you in which branch you are by using ''__git_ps1''. For example you can replace your default prompt in your ''~/.bashrc'' file with:
  
  bash
 
 
   if [ "$color_prompt" = yes ]; then
 
   if [ "$color_prompt" = yes ]; then
 
       PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[00;32m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
 
       PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[00;32m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '

Revision as of 08:45, 7 May 2014

If you are not familiar with git we suggest at least you learn the basics. The official and comprehensive man pages are included in the Git package itself. You can access to them with:

  git --help
  git <command> --help

Quick Git Setup

Setup SSH Keys

You can use git with https, but this requires to insert the username and password every time you need to push on the server (and to fetch or pull if the repository is private). Using ssh will save you some precious time. In order to use ssh you have to create an ssh key and add it to your profile on GitHub.

Your Identity

The first thing you should do is to set your user name and e-mail address.

 git config --global user.name "John Doe"
 git config --global user.email "john.doe@example.com"

Some Color

If you use git mostly from the command line, colors are very useful, you can enable them by running:

 git config --global color.pager true
 git config --global color.ui auto

Bash Prompt

Bash prompt can be tweaked to show you in which branch you are by using __git_ps1. For example you can replace your default prompt in your ~/.bashrc file with:

 if [ "$color_prompt" = yes ]; then
     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[00;32m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
 else
     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (%s)")\$ '
 fi

More

A few more setup tricks can be found here:

  http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup

A very comprehensive source of documentation is this:

  http://git-scm.com/documentation

More tutorials can be found here:

  http://sixrevisions.com/resources/git-tutorials-beginners/

If you are a subversion user, you might find useful this crash course for svn users. Please note that git and svn workflows are slightly different, this is only supposed to be used as reference.

  http://git.or.cz/course/svn.html