User:Timothee Flutre/Notebook/Postdoc/2012/08/14

From OpenWetWare
< User:Timothee Flutre‎ | Notebook‎ | Postdoc‎ | 2012‎ | 08
Revision as of 13:50, 14 August 2012 by Timothee Flutre (talk | contribs) (Entry title: first version)
Owwnotebook icon.png Project name <html><img src="/images/9/94/Report.png" border="0" /></html> Main project page
<html><img src="/images/c/c3/Resultset_previous.png" border="0" /></html>Previous entry<html>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html>Next entry<html><img src="/images/5/5c/Resultset_next.png" border="0" /></html>

About Git

  • Motivation: nowadays, it's pretty common to use a computer for a project in which one wants to: keep history of the changes, access them on different operating system, share our work with someone else, etc. In such cases, it's very useful to use a distributed versioning system, such as Git. Typical cases are when developing a software or writing an article.
  • Writing a paper: in this example, I am writing a paper with two colleagues. We decide to do it as a centralized workflow, the shared repository being hosted by github.
    • Each of us needs to create a free account.
    • I need to upgrade my account in order to have the right to manage private repositories ($7/month).
    • I create a private repository named "paper" and add my colleagues as collaborators to it.
    • I retrieve the repository on my local machine: git clone git://
    • I create some files, for instance README and paper_main.tex, and add them to git in my local repository: git add README followed by git commit -m "first commit" README
    • I create one branch per collaborator (the default branch being "master"): git branch tim, then git branch colleague1 and finally git branch colleague2. I can list the local branches with git branch and I can switch to my branch with git checkout tim for instance.
    • I push the changes I made from my local repo onto github: git push origin master, this for each branch I created.
    • I send an email to my colleagues telling them that they can retrieve the content of the repository from github into their local machine(s): git clone git://
    • Each of us can make modifications on its own branch, and push them on github in order to allow the others to access the changes.
    • From time to time, one of us has the responsibility to merge the changes and update the "master" branch with the latest version.
    • Once this is done, the others need to retrieve the new content of "master" in their local repo: git checkout master, git fetch origin, git diff master origin/master, git merge origin/master.
    • Then, they need to update their local branch with the new content of "master": git checkout colleague1, git diff --name-status colleague1..master. This will list the files having differences between their local branch and the new content of "master".
    • One can look at the differences file by file: git diff --color-words colleague1:paper_main.tex master:paper_main.tex. The options "--color-words" is especially useful in LaTeX.
    • To merge the content of "master" into his own branch, we do: git merge master.
    • In case of conflicts, we have to edit our own files by hand. Or we can also choose to ignore the conflicts and overwrite our local files with the content of "master": git checkout --patch master paper_main.tex.