Git usage

User Infos

  • set your used id and mail
    • git config --global user.name some.body
    • git config --global user.email some.body@cern.ch

File handling

  • adding a file/directory
    • git add ./PATH/TO/SOMETHING
  • removing from the local repository and from the disk
    • git rm ./PATH/TO/SOMETHING
    • just removing from the repository and keeping the file on disk
      • git rm --cached ./PATH/TO/SOMETHING
  • moving
    • git mv ./PATH/TO/SOMETHING  ./PATH/TO/SOMEWHERE/ELSE

  • commiting changes in the local repository
    • git commit -m "a comment what happened here" (with -a an implicit add is done)

Branches

  • to switch to another branch

Change Log and Tagging

  • to see the history of changes in the current branch
    • git log

  • check the specific changes that were applied in the commit with hash 123456789abcdefg1011121314
    • git show 123456789abcdefg1011121314

  • to tag a certain change with the commit hash 123456789abcdefg1011121314
    • git tag TestTag1.1 123456789abcdefg1011121314
    • just git tag TestTag1.1 tags the most current change

Communicating with a remote repository/user

  • see, which other users/repositories exist
    • git remote -v

  • to push the from the local repository the branch BRANCH to the remote user origin
    • git push origin BRANCH

  • to fetch from the remote repository origin the branch BRANCH and merge it into your local branch
    • git pull origin BRANCH
    • to fetch only the changes do, i.e. get only the information about remote updates without changing the actual local files
      • git fetch origin BRANCH
    • to do only a merge of changes from branch BRANCH into the local files of the active branch do
      • git merge BRANCH


ignoring files

  • some files are probably not useful to be tracked, e.g. compiled libraries or binaries *.pyc,...
    • for a specific repository a =.gitignore=-file can be filled with the file names to be ignored
    • globally ignoring files in all repositories a file as .gitignore_global can be placed in the home directory and added to the git-configuration with git config --global core.excludesfile ~/.gitignore_global
      • the file could contain exclusions like
        *.o
        *.so
        *.pyc
  • this should fix some of the git messages Your branch is ahead of 'origin/master' by # commits.

merging only smaller changes between branches

  • for exchanging only small changes between branches, the cherry-pick command can be used, e.g. in a =beta=-branch a small bug-fix works and one would like to implement the fix already in the =master=-branch without merging the branches completely.
    • first: move to the =beta=-branch and check, in which commit the bug-fix was added.
      • git checkout beta
        git log -1
        • commit 67f90a0768efc5eb...
    • move to the master=-branch and =cherry-pick this commit to be merged
      • git cherry-pick 67f90a0768efc
    • (resolve any conflicts)
-- ThomasHartmann - 22-Mar-2012
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r5 - 2012-03-29 - ThomasHartmann
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    LHCb 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