Git Guide

Created by Linus, it's a great versioning system for software. Especially useful when you have lots of people developing simultaneously on lots of different versions of software. Used from large projects such as the linux kernel down to a paper written in latex between a few people.

Obtaining

You can get Git easily using Macports. Search for it port search git.

Using

Typically command line. A great free GUI is SourceTree. The GUI is useful to visualise what is going on and to commit only certain lines of a file very easily.

Webpage guide I found here.

Stick to this convention. Print it out.

My notes below:

Commands

GET CHANGES
git pull

SEND CHANGES
git push

PUSH PULL - WHICH ORDER
you’ve committed things locally and want to push them - push fails as the server has changed (“your branch is behind the tip”). To avoid this, do your commits, then PULL, then PUSH.

COMMIT
the saves the changes
git commit -a -m”your message”
-a means stage all changed files (careful!)
-m the commit message for that change

CHECKOUT
changes your current view / branch you’re on.  changes the contents of the folder - only do from the root of the repository - ie not in a subfolder.
git checkout branchname
ie
git checkout develop

master is always the default branch in any repository and develop is the most common one to work in, so usually when you get a repository, you need to checkout the develop branch


VIEW ALL BRANCHES
git branch -a

CREATE A BRANCH
How to create a branch.  Merge is into what you're working locally on.  Use checkout to change 'focus' of what you're on now.


git fetch origin  #get status update from server
git checkout branchA
git merge master
     uh oh - resolve conflicts here
git checkout master
git merge branchA
git pus origin

CREATE A BRANCH USING CURRENT CHANGES
So you’ve worked in develop and changed things and want to move the current changes into a branch:

git checkout -b newbranchname
maybe have to do a commit now


MERGING / RESOLVING CONFLICTS

setup merge tool to meld

sudo port install meld
git config --global merge.tool meld 
launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist 


DELETE A BRANCH
 - make sure you're not in a branch
 - by checking something else

git branch -D branchname

DELETE A REMOTE BRANCH
git push origin —delete branchname   

WHEN IN YOUR BRANCH
git merge sourcebranchname

do this often while in my feature branch to pull in the changes into my branch from sourcebranchname

RESET STUFF
git reset HEAD --hard
git clean -fd

SUBMODULES INIT
git clone —recursive 

initialise submodules too

SUBMODULE UPDATE
git submodule update

-- LaurieNevay - 25 Sep 2014

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...

Physics WebpagesRHUL WebpagesCampus Connect • Royal Holloway, University of London, Egham, Surrey TW20 0EX; Tel/Fax +44 (0)1784 434455/437520

Topic revision: r1 - 25 Sep 2014 - LaurieNevay

 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback