git basics
Outline
Why Version Control? Terminology Getting Started Initializing Repo Adding Files Viewing Changes Committing Typical Cycle Working with Remote Repo Resolving Conflicts Co-operative Cycle Additional Info
Why Version Control?
Single users
often we work on documents (or a set of files) for a long time (days, weeks, months) we (should) have backup copies in other places need to know:
regularly: what is the most recent version sometimes: how did the project look like some time ago (say two weeks)
Common approach:
file-1.doc file-2.doc file-2a.doc file-3.doc
In team work:
multiple people working on code may work on one file simultaneously need
tracking of versions merging of changes from different people
Impossible to do manually => Need version control
Terminology
Repository
keeping track of all changes to the project for all the past (hidden in .git) abbreviated repo the set (visible) files (in the working directory)
Working tree
Getting Started
Installation
$ yum install git $ git config --global user.name "Your Name" $ git config --global user.email you@redhat.com
Before starting to use git
Initializing Repo
Initialize repo
$ cd /path/to/your/working/dir $ git init
Adding Files
Add the new files you want to track changes
$ git add file1 file2 ...
Add the changes that you have made to previously added files
$ git add changed-file1 changed-file2 ...
Add all the files (including sub dirs) under current dir
$ git add .
Viewing Changes
Launch a diff view of the changes you have made (and not added yet)
$ git diff
Committing
Commit the added files/changes
$ git commit
The default text editor (usually vi) will be invoked to ask you to enter the commit message.
View the commit history
$ git log
Typical Cycle
1. do the work (i.e. modify files) 2. add the changes 3. commit changes with commit message 4. back to 1.
Working with Remote Repo
Clone a remote repo into your local storage
$ git clone remote repo address $ git pull $ git push
Keep up to date with the remote repo
Submit local commits to remote repo
Resolving Conflicts
When more than 2 people are working in parallel, conflicts might happen when pulling.
Conflicts resolving steps
Find out the conflicts using git-diff.
$ git diff
Review the conflict carefully. Modify the code to the correct version. Add the file that contains the conflict
$ git add file1 file2 ... $ git commit
Commit the changes
Co-operative Cycle
Co-operative working cycle
$ git clone remote address ... modify code ... $ git add changed files and new files $ git commit $ git pull ... resolve conflicts ... $ git push
Additional Info
git server here in nay
http://qe-git.englab.nay.redhat.com/ $ git clone git://qe-git.englab.nay.redhat.com/linux2.6 $ git push git+ssh://git@qegit.englab.nay.redhat.com/home/git/repo/linux-2.6
cloning
pushing
Thanks!
Jinxin Zheng <jzheng@redhat.com>