Main difference between GIT and CVS or SVN is in GIT most of the work(commit, revert, rebase, merge) happens locally in you repository. # git clone command make your local repository. So GIT needs in 2 additional commands to synchronize you local repository with central one.

GIT simplest workflow directly in 'master' branch(CVS-style)

1. Clone repository to you home directory(# cvs checkout):

# git clone

# cd AMS-geant4

2. Make some changes or add/delete files

3. Add files to commit and commit the changes(# cvs add for new files):

# git add file1 file2 file3

# git commit -m "some useful comment"

4. Push your changes to the central repository(# cvs commit):

# git push origin master

GIT workflow with branches

Basically it is good practice when for one task creates one branch. New build merges all resolved tasks to another branch, run build commands, tests and other check stuff. When build is checked and realized branch merges to the master. In this case, we can ensure that the code in 'master' branch is always clean and ready for production.

1. Switch to local master branch

# git checkout master

2. Make sure your tree don't have any modifications:

# git status

3. Pull remote master(called origin master):

# git pull origin master

Actually # git pull command is a set of git fetch & get merge commands. git fetch command just fetch changes from remote repository to your local and git merge command merge thigs changes to your current branch(in this example "master"). In this point you have fresh master branch in your local repository(like after "cvs up") from witch you can start new development.

4. Create and switch to new branch:

# git checkout -b my_new_branch

5. Make some changes or add/delete files

6. Commit your changes

# git commit -m "commit message" file1 file2 file3

7. Push your changes to remote repository.

# git push origin my_new_branch

In this point another user can fetch your branch and review your work for example. Or merge your changes in himself branch.

Real example from the beginning

I have a task to modify files CC/crc.C and CC/crcj.C. I have just cloned repository after git clone command.

1. I cd to the repository folder and make new branch:

# cd AMS

# git checkout -b AMSSOC-22_support_cksum_crc

2. Next I make my changes, commit them to my local repository:

# git commit -m "add common crc32 algorithm calculation" CC/crc.C CC/crcj.C

3. And then I push my local branch to remote repository:

# git push origin AMSSOC-22_support_cksum_crc

From this point anybody can fetch this branch and view my changes. For example Baosong want to do it and he have clear local repository(without any modifications).

1. Make sure he in a master branch

# git checkout master

2. Fetch and merge all new changes and branches:

# git pull origin master

3. Checkout to my branch:

# git checkout AMSSOC-22_support_cksum_crc

4. View the changes

# git show <commit_id>

This flow adds 2-3 additional commands for each user, but guaranty clear master code branch. You can anytime fix small critical bug and start build process from it without global modifications in users branches.

~/.gitconfig file example

    branch = auto
    diff = auto
    interactive = auto
    status = auto
    name = Your Name
    email =
    editor = vim

Other things

Use # git status command to view you local changes and status of you repository. In most cases this command will show you what you can do in currently state.

Use # git branch to know what branch you are currently in.

Use # git log to view commit history.

Use # git show <commit_id> to view commit diff of selected commit_id

Use # git stash to stash your local modifications, do another useful stuff with clean repository and # git stash apply to return your modifications.

Use # git rebase -i HEAD~3 to interactively rebase 3 last commits(change commit message, merge all 3 commits into one, etc).

Use # git cherry-pick <commit_id> to fetch and apply commit_id to your local repository

CERN GIT tips and tricks:

-- OlegDemakov - 2015-03-13

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r4 - 2015-03-20 - OlegDemakov
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    AMS All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback