26/09/2010 Git FAQ

I started using Git about 6 months ago in an every day bases and this remains one of the best decision I ever took on the regard of development.

However, like my friend Guillaume Chevallereau said to me when I started: When you start using Git you must "unlearn" everything you learn before. This is true! So true that I would advice beginners to start with Git (or Mercurial) but absolutely not with CVS or SVN because those version control systems are simply build upon wrong concepts.

I think that using Git wisely allows much more efficient developments than SVN, especially over time. All projects that live long enough take more and more time to develop because of project complexity. This rule implies that a project must be build with small modules to ensure that the development time isn't going to grow expentionally. Moreover, I think that rewritting a project is completely stupid and a waste of time. On the contrary, rewriting a part of a project, even an entire module, is ok with good reasons.

Git is a layer on top which ensures that the development strategy is going to be apply nicely, without poluting the code, allowing developers to work together in parallel to build over time a great code. I'm glade to see that I am not the only one to care about the development process and the key values of great code. Git is a key element for such archivement.

In this post I would like to start some sort of a FAQ for Git.

1 - How to access to a git repository and branches?
  • git clone $REPOSITORY_URL
  • git checkout 0.9.1
  • git checkout master

With Git, we don't only 'checkout' a repository, we 'clone' it that is to say that each copy of the repository is a fully functional and working repository totally independent from the 'origin' repository. 'checkout' with Git only means changing branch. In the previous command line, the 'origin' repository is the one located at $REPOSITORY_URL.

2 - How to commit with Git?
  • Display the list of changes to commit, changes but not added for commit and the untracked files and directories.
  • git status
  • git add $CHANGED_FILE_OR_DIRECTORY
  • git commit -m "My comment for my changes"

'status' gives a complet report on the state of the repository directory. Git is based on 'changes' not 'file versions'. We don't add files to the repository we add changes. For every changes we must add them before commiting them. If a file changes and this change is added to be commited. Further changes won't be commited with the first change if they are not added as well before the commit.

3 - How to get changes from others repositories?
  • git pull origin master
  • git pull $BOB_URL bob_ultimate_feature

'git pull origin master' is the closer command to 'svn update' on the trunk. This command line fetch the changes of the master branch from the repository we cloned and 'merge' them on our current branch. We can also get changes from any remote repository and any branch.

4 - How to send changes to other the origin repository?
  • git push origin master

Even if I am not a fan of it, it's the only way to share changes between developer through the SourceForge.net server. Instead I'll rather ask the server to pull my changes or directly another developer if he is on the same network than I.

5 - How to branch and merge?
  • Display our repository branches
  • git branch
  • Display the remote branches
  • git branch -r
  • Checkout my_branch from our repository or a remote repository
  • git checkout my_branch
  • Create a branch call my_feature and checkout it out
  • git checkout -b my_feature
  • git checkout my_branch
  • Merge my_feature branch to the current branch
  • git checkout merge my_feature
  • Delete the branch my_feature
  • git branch -d my_feature

Thanks to its "changes oriented design", Git provides a powerfull branching mecanisum that can and should be use without restriction. When a branch is created or deleted on the local repository, it isn't created or deleted on the remote repository. To create a branch on a remote directory it has to be push or pull explicitly.

To be continued...

G-Truc Creation 6.5.1.0 source released >
< Texture compression formats: lost in translation
Copyright © Christophe Riccio 2002-2016 all rights reserved
Designed for Chrome 9, Firefox 4, Opera 11 and Safari 5