Presentation drawing

Git for n00b

The Adventure Begins

Here we go!

Here is one from many way to use Git. This method is sufficient to work on a project. Not there is many other workflows.

Basic usage

Work with Git immediately:

  • Get modification done by others git pull,
  • See details of these modifications git log,
  • Many times:
    • Make an atomic modification
    • Verify details of this modification: git status and git diff,
    • Add some file to be versionned if necessary:
      git add [file],
    • Save you modifications
      git commit -a -m "message",
    • Send your modifications to others: git push (redo a git pull if push return an error).

With these few commands you can use Git. Even if it is sufficient, you need to know one more thing before really begin ; How to manage conflicts.

Conflicts management

Conflicts can arise when you change the same line of code on the same file from another branch you’re merging. It can seems a bit intimidating, but with Git this kind of thing is really simple to handle.

example

You start from the following file

Zoot 

and you modify one line

Zoot the pure

except during this time, another user had also modified the same line and had done a push.

Zoot, just Zoot

Now when you do a:

$ git pull
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/e640846/tmp/conflictTest
   d3ea395..2dc7ffb  master     -> origin/master
Auto-merging foo
CONFLICT (content): Merge conflict in foo
Automatic merge failed; fix conflicts and then commit the result.

Our file foo now contains:

<<<<<<< HEAD:foo
Zoot the pure
=======
Zoot, just Zoot
>>>>>>> 2dc7ffb0f186a407a1814d1a62684342cd54e7d6:foo

Conflict resolution

To resolve the conflict you only have to edit the file for example, writing:

Zoot the not so pure

and to commit

git commit -a -m "conflict resolved"

Now you’re ready to use Git. Git provide many other functionnalities. Now we’ll see some Git usages older CVS couldn’t handle.

comments

Copyright ©, Yann Esposito
Created: 11/12/2009 Modified: 05/09/2010
Entirely done with Vim and nanoc
Validation [xhtml] . [css] . [rss]