Git Basic
Git Basic
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
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:
In team work:
multiple people working on code may work on one file simultaneously need
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 [email protected]
Initializing Repo
Initialize repo
Adding Files
Add the changes that you have made to previously added files
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
$ git commit
The default text editor (usually vi) will be invoked to ask you to enter the commit message.
$ 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.
Resolving Conflicts
When more than 2 people are working in parallel, conflicts might happen when pulling.
$ git diff
Review the conflict carefully. Modify the code to the correct version. Add the file that contains the conflict
Co-operative Cycle
$ git clone remote address ... modify code ... $ git add changed files and new files $ git commit $ git pull ... resolve conflicts ... $ git push
Additional Info
cloning
pushing
Thanks!
Jinxin Zheng <[email protected]>