You are viewing the old homepage of Jürgen Sturm which is no longer updated (as of March 1, 2011).
The new homepage is located here: http://vision.in.tum.de/members/sturmju.
You are viewing the old homepage of Jürgen Sturm which is no longer maintained (as of March 1, 2011).
The new homepage is located here: http://vision.in.tum.de/members/sturmju.

Frequently used git commands

Introduce yourself to git

Set up your email adress:

git config --global user.email johndoe@example.com

Set up your name:

git config --global user.name 'John Doe'

Pick a merge tool (for example, meld or emerge):

git config --global merge.tool meld

Initial checkout

Checkout the zora repository:

git clone aishome.informatik.uni-freiburg.de:/home/aishome/sturm/git/zora

Note: This will give you a working copy of the current master-branch.

Create your own branch

Note: Skip this if you have already created your branch before.

Create a new branch called 'student1' in the remote repository (based on the remote master branch):

git push origin master:refs/heads/student1

Update the branch list in the local working copy:

git fetch

Checkout a branch

Checkout your (newly created) branch locally:

git checkout --track -b student1 origin/student1

To make updating/merging easier later on, I recommend to only track your branch and stop tracking the master branch:

git branch -D master

To view the currently tracked branches:

git branch

To view all branches

git branch -a

Typical work cycle

Now you can begin to work, change files, etc. It is good practice to “commit early, commit often”.

Show a list of changed/unversioned files in the working directory:

git status

Inspect changes in more detail:

git diff

Revert changes since last commit made in working directory:

git reset --hard

Then either: Add some files for commit:

git add src/robot/...
git commit

Or: And and commit all changed/newly created files in working directory (advice: first check what would be added using 'git status')

git commit -a

Finally: Copy this local commit to the remote repository:

git push

Merging/Rebasing

There are two different ways in git to keep your branch up-to-date with changes in the master branch. As far as I see, it is recommended to use “rebase” for copying new features of the master branch into your branch, while you should use “merge” when you want to merge the updates of a branch into the master-branch. However, both will work, and the only difference in the end is the history: with re-base, the history will be linear (the master branch, and your branch will be attached upon the latest master revision), while with merge, the history will contain two parallel branches (your branch and the master branch), that are fused together by the merge commit.

In both cases, note that git requires that you have commit all of your local changes to your branch. Therefore, before merging/rebasing, ensure that this is the case.

Check whether your working copy is clean (should report: “nothing to commit” or “nothing added to commit but untracked files present”):

git status

Rebase

Get the changes from the remote repository:

git fetch

Now rebase your branch on top of the master branch:

git rebase origin/master

Conflicts while rebasing

It will (often) happen that you get conflicts during rebasing that you need to resolve manually.

Start the merge tool, and resolve the conflict:

git mergetool

Continue rebasing:

git rebase --continue

If you decide to keep your version of the file, git rebase –continue will complain that you did not incorporate any changes from this patch. It will say:

 No changes - did you forget to use 'git add'?

The correct way is then to tell git explicitly that you do not want this specific patch:

git rebase --skip

Merge

Get the changes from the remote repository:

git fetch

Then start the merge (merge the updates from the master branch into your branch):

git merge origin/master

If no conflicts occur, git merge will automatically create a new commit corresponding to the merge.

Conflicts while merging

It will (often) happen that you get conflicts during the merge that you need to resolve manually.

Start the merge tool, and resolve the conflict:

git mergetool

Finally, commit your changes (after a manual merge):

git commit

Working with tags

Creating tags (for stable versions)

You can add tags to a revision, for example to mark it as a “stable” release:

git tag zora_release_0.7.4

Then, push the tags to the remote repository:

git push --tags

Test builds and automatic tags

There is a script called utils/testbuild, that performs a test build of the current branch and, if this build succeeds, adds a automatic tag to this commit in order to mark it stable.

utils/testbuild

Checking out tagged revisions

In order to check out a tagged revision, use

git checkout zora_release_0.7.4

To return to the head of the master branch, use

git checkout master

Creating new repositories

Create a remote repository:

mkdir -m 770 /pub/git/new-repos
chgrp git-zora /pub/git/new-repos
cd /pub/git/new-repos
git --bare init --shared=group

First checkout:

mkdir /tmp/checkout
cd /tmp/checkout
git init
git remote add origin /pub/git/new-repos

First change, first push:

touch .gitignore
git add .
git commit -m "Initial commit"
git push --all
git 

More

last modified on 2008/12/09 18:21