|
|
Git TutorialTable of contents
This tutorial should give an overview of how to use git at the example of gromacs. The number of useful git commands increases exponentially with the amount of changes you have to manage, that is why we will part the users in 4 groups:
NoviceGetting your own copy of the gromacs repository is very simple, just run: git clone git://git.gromacs.org/gromacs.git (If you have problems connecting, because you are behind a proxy, see the Tips & Tricks section.) The clone command will also checkout the most recent (developer) version for you. The directory created contains two parts
Stable versionMost likely you want to work with the stable version (version 4.0 + all the bugfixes) instead of the developer version. The best way to do so, is to create a tracked branch. Enter your gromacs dir and execute git checkout --track -b release-4-0-patches origin/release-4-0-patches This will create a local tracked branch (named release-4-0-patches), which follow the release-4-0-patches branch of the origin repository. For more infos about branches see the Normal User section. UpdatingFrom time to time you should update your repository by running git pull which will download all the changes from the origin destination (where you cloned from before, most likely git://git.gromacs.org/gromacs) and merge them into your working copy. This should work without any problem when working with a unchanged version of gromacs. It also works branch wise if you are on a tracked branch (see stable verision section). Take a look at the changesa nice graphical interface to view changes is gitk but the main (summary) informations about the changes you can see with git log To see the changes in the source code (the actual patch) take a look at the Normal User section. StatusYou can easily find out which files don't belong to repository with git status in most cases you will see a lot of object files (.o) and stamp files from the build process. # On branch release-4-0-patches ........... Normal UserPlease read und understand the Novice section first. Adding your own stuffTo add some extra stuff to your cloned gromacs repository, just copy the files into your gromacs dir and execute git add file1 file2 ... after that you can check the status git status the message should contain something like: # On branch master now you are ready to commit git commit -m "Added my own stuff" verify the result with git log -1 which should tell something like: commit 7c92c1f9bcd87d05e8a43757cdd845d7ba76a526 (if you don't like what it says at author, see the Tips & Tricks Section) UpdatingThis works in the same way as before, just run git pull as pull is the combined operation out of fetch and merge, your repository will include an automatically commit message (use "git log" to view it) like this: commit 95297300261032063632c9fe77578133cc40a6a7 To understand this effect, we have to take a look at branches. BranchesBranches come completely natural in git (not like in cvs, where you to create them). Let's you make one commit in location1 and other commit in location2, so both location locally follow the trunc, but seen on the global scale the repository was branched. But this is nothing bad, "git pull" will just merge the two branches to a new trunc. This is one of the stength of git, like Towalds Linus says: "Merging should be easy not branching". Merge vs. RebaseAs said before git pull internally does something like git fetch git merge FETCH_HEAD BugfixesThe following are the recommended steps to submitting bug-fixes.
If one has only commits in the release branch which shouldn't be merged into master one can do: git merge -s ours release-4-5-patches
Keeping your version in sync at different placesDue to the fact that git is distributed version managment system you can simply clone the gromacs version with your own changes to a new location git clone path/to/yourgromacs another_repo git is smart enough to clone over ssh git clone ssh://somecomputer/~/path/to/gromacs repo_here (~ is as usual your home). If you have done changes in location1 you can use pull from location2 to get them location1> git pull location2 The "opposite" of pull is push. This make it possible to push your changes to another place location2> git push location1 But attention, git will never touch the remote working dir, so you have to execute: location1> git checkout HEAD in location1, to checkout the newest revsion, called HEAD.
|