Git tips from work

Published: Saturday, Dec 13, 2008 Last modified: Thursday, Nov 14, 2024

[[toc ]]

Getting started

Read the git tutorial. You need to at least set up your config variables.

Install git on Darwin

Install fink, use unstable sources.

Git package in Fink

Install on Debian

Easy: apt-get install git-core

Tracking WebKit git and our patches against it

How the WebKit mirror was constructed:

mkdir /srv/git/webkit
cd /srv/git/webkit
nox:/srv/git/webkit% git --bare init --shared
nox:/srv/git/webkit% git --bare fetch git://git.webkit.org/WebKit.git master:master
git fetch -f git://git.webkit.org/WebKit.git master:master # and again later forcing updates

touch git-daemon-export-ok
echo ssh://git.webvm.net/srv/git/$(basename `pwd`) > cloneurl

This could be wrong. Maybe I should have:

git remote add webkit git://git.webkit.org/WebKit.git
git fetch webkit

I posted to the git mailing list to ensure I am doing this right (I am). Unfortunately when you work on a WebKit branch you need make a complete checkout. You really can’t get around that.

gitweb.cgi configuration for public and private repos

/var/cache/git has been split out into private and public:

nox:~% cat /srv/www/git.webvm.net/.htaccess
SetEnv GITWEB_CONFIG /srv/www/git.webvm.net/gitweb.conf
nox:~% egrep 'projectroot =' /srv/www/git.webvm.net/gitweb.conf
$projectroot = "/var/cache/git/public";
nox:~% egrep 'projectroot =' /srv/www/g.webvm.net/gitweb.conf
$projectroot = "/var/cache/git/private";

Setting up projects to be public:

nox:/var/cache/git/public% sudo ln -s /srv/git/backup
nox:/var/cache/git/public% sudo ln -s /srv/git/runtest

Developer working cycle

Use case: We are working with directfb code base. We need a central location to manage our changes.

The ssh:// URL can be found from the web interface.

As a developer using the code base of an opensource project, you will want to a seperate branch with: git-checkout -b $BRANCHNAME. Could I please suggest calling $BRANCHNAME you want people to look at as $USER, though perhaps naming $BRANCHNAME as a particular feature is wiser.

Create as many branches as you like, though to let people see your work, you need to push back with git push origin $BRANCHNAME.

Converting from Subversion to Git

  1. Create the git repo on example.com git --bare init --shared in a dir called ‘/srv/git/oldsvn’
  2. git-svn clone $SVN_URL # svn checkout your subversion repo you want to migrate to git
  3. git push ssh://example.com/srv/git/oldsvn --all

Pushing sources to a newly created git repository

git init
git add .
git commit -a -m "initial"
git-config remote.origin.url ssh://git.webvm.net/srv/git/runtest
git push --all

Q&A

Git has a bit of a steep learning curve. Please add you findings below:

Q: how do i get the last commit id (current version), without say using git log --pretty=oneline | head -n1?
A: git-rev-parse HEAD
Q: How do I see all branches?
A: git-branch -a
Q: What does a git-pull do?
A: It is a git fetch origin and then a git merge origin
Q: How do I find out what’s new before I do a pull?
A:
  1. git fetch origin
  2. git log master..origin/master
Q: How do I quickly clean up untracked (e.g. build residue) files?
A: git clean -d
Q: How do I make a remote branch local?
A:
git branch -a # to find name of $remote
git checkout -b $remote origin/$remote
Q: “git diff 08762e852c49709a22ef8fd9c82bb6a6b28ed91b” is not showing the same as http://....git;a=commitdiff;h=08762e852c49709a22ef8fd9c82bb6a6b28ed91b
A:
git show 08762e852c49709a22ef8fd9c82bb6a6b28ed91b
Q: Oops! I accidentally added private/personal/health.txt
A:
git rm -f --cached private/personal/health.txt
Q: How do I correct a bad commit log?
A:
git commit --amend
Q: How do I configure git commit to be more like svn commit?
A:

With git, commiting changes should require a git add file and then a git commit. Most people get around this boring default behaviour by issuing git commit -a all the time. But if you can’t be bothered to type in a “-a” switch all the time, create an alias with in your ~/.gitconfig, like so:

git config --global alias.ci 'commit -a'

Then svn style svn ci should work for committing:

git ci
Q: What’s the difference between master and head?
A:
Q: Oh no I have loads of conflicts to manage! HELP?!
A:
git-mergetool -t vimdiff

It’s a bit scary. Try understand how everything works in a test repo… git init in /tmp/foo and go from there.

Q: Can I get git to work with CVS?
A:

See this Git CVS workflow tutorial.

Q: How do I svn revert a single file “platform.html”?
A:
git checkout platform.html
Q: How do I unadd a file?
A:

To see the paths:

git-status

Notice the odd ‘–’

x61:~% git reset -- code/trunk/tests/html/logs/index.cgi

or:

git rm --cached aplix/code/trunk/tests/html/602/index.html
Q: How do I wipe the history of a git repo ? (you probably don’t want to do this!)
A:
rm -fr .git
git init
Q: How do I do a colour diff between two files ‘foo’ and ‘bar’ that aren’t in git?
A:
git diff --color-words --no-index foo bar
Q: Git and CVS?
A: See the [[Git_CVS_Tip|09017]]
Q: How do I find even more tips? :)
A: Checkout Git blog posts