|
|
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.5 + 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-5-patches origin/release-4-5-patches This will create a local tracked branch (named release-4-5-patches), which follow the release-4-5-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 version 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 Power UserKeeping 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. DeveloperMerging bug fixes into development branchesThe following are the recommended steps for incorporating bug fixes into development branches.
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 Private BranchesGerrit allows to have private branches (refs), for which you can set own permssions, see Admin/Project/Access
[remote "private"]
fetch = +refs/private/USER/*:refs/remotes/private_USER/*
url = ssh://USER@gerrit.gromacs.org:29418/gromacs
push = refs/heads/private_USER/*:refs/private/USER/*
After that do a git pull private and create a tracked branch git checkout -b BRANCH --track private_USER/BRANCH Remeber to replace BRANCH and USER in the above commands. Tips & TricksGit behind a proxygit knows about http_proxy environment variable, but tunneling the git procotoll is sliently more complicated:
#!/bin/bash socat STDIO PROXY:your_proxy:$1:$2,proxyport=your_proxyport
export GIT_PROXY_COMMAND=git-proxy.sh Your own gromacs mirrorCreate a gromacs mirror for your group is very easy. git (>=1.6) has already everything onboard, just run: git clone --mirror git://git.gromacs.org/gromacs That's it, the only thing left to do is to create a cronjob running git fetch every hour. To give the mirror a nice small http interface run: git instaweb (you will need lighttpd for that). Now the http interface can be seen at: http://localhost:1234 and http://your_hostname:1234 your whole intranet can use this mirror to clone with git clone http://your_hostname:1234 In nearly the same way the mirror on repo.or.cz was created. Introduce yourself to gitgit has a global and repository wise place to save personal setting git config --global user.name "Superman" git config --global user.email "kent@metropolis-press.com" leave away --global to make a repository wide change. Colorsare nice and useful, so enable them: git config --global color.ui "auto" |