From ArchWiki
Revision as of 11:17, 29 July 2011 by Stfn (Talk | contribs)

Jump to: navigation, search

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki: Generally about contributing to pacman, although it still serves as a practical Git tutorial Template:Article summary wiki Template:Article summary end

Git is the version control system (VCS) coded by Linus Torvalds (the creator of the Linux kernel) after being criticized for using the proprietary BitKeeper with the Linux kernel. Git is now used to maintain sources for the Linux kernel as well as thousands of other projects, including Pacman, Arch's package manager.

There is extensive documentation, guides, and tutorials available from the official web site.


Template:Package Official can be installed with pacman as usual from the [extra] repository. Pay attention to the optional dependencies if you care about using Git with other VCS software, mail servers, or using Git's GUI.

Bash completion (eg. hitting tab to complete commands you are typing) should work if you

source /usr/share/git/completion/git-completion.bash

Alternatively, you can install the Template:Package Official package to load the completions automatically for new shells.

If you want to use Git's built-in GUI (eg. Template:Codeline or Template:Codeline) you should install the Template:Package Official package or you'll get a rather cryptic message:

/usr/bin/gitk: line 3: exec: wish: not found.


Git reads its configuration from a few INI type configuration files. In each git repository Template:Filename is used for configuration options specific to that repository. Per-user ("global") configuration in Template:Filename is used a s a fall-back from the repository configuration. You can edit the files directly but the preferred method is to use the git-config utility. For example,

$ git config --global core.editor "nano -w"

adds Template:Codeline to the Template:Codeline section of your Template:Filename file.

The man page for the git-config utility has a fairly long list of variables which can be set.

Here are some more basic configurations you will probably want:

$ git config --global "Firstname Lastname"
$ git config --global ""
$ git config --global color.ui true


Parts from everywhere, much from the wonderful tutorial here:

Additionally see Super Quick Git Guide.

Pull the network scripts with

git clone

Update an existing clone

git pull origin

Commit changes

git commit -a -m "changelog message"

To create a new branch

git branch somebranch

Change to a different branch

git checkout differentbranch

Merge a branch to current active branch

git merge somebranch

Delete a branch

git branch -d somebranch

Diff between two branches

git diff master..somebranch

Diff between two commit ID's (found in git log)

git diff e9780c7cba2855350e914fde227a79bb63c1351d..8b014e40346b38b3b9bfc41359b4e8a68e804c0d

Diff between the last two commits

git diff HEAD^ HEAD

Patchset between two branches (follows same syntax as git diff afaik)

git format-patch master..somebranch

Or better:

git format-patch -o out origin

Set nano as default editor

git config --global core.editor "nano -w"

Start remote repository [broken as of 31DEC10]

Transfer Protocols

Smart HTTP

Since version 1.6.6 git is able to use the HTTP(S) protocol as efficiently as SSH or GIT by utilizing the git-http-backend. Furthermore it's not only possible to clone or pull from repositories, but also to push into repositories over HTTP(S).

The setup for this is rather simple as all you need to have installed is the Apache webserver (with mod_cgi, mod_alias, and mod_env enabled) and of course, git:

# pacman -S apache git

Once you have your basic setup up and running, add the following to your Apache's config usually located at /etc/httpd/conf/httpd.conf:

<Directory "/usr/lib/git-core*">
    Order allow,deny
    Allow from all

SetEnv GIT_PROJECT_ROOT /srv/git
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

The above example config assumes that your git repositories are located at /srv/git and that you want to access them via something like http(s)://your_address.tld/git/your_repo.git. Feel free to customize this to your needs.

Note: Of course you have to make sure that your Apache can read and write (if you want to enable push access) on your git repositories.

For more detailed documentation, visit the following links:


You first need to have a public SSH key. For that follow the guide at Using SSH Keys. To setup SSH itself you need to follow the SSH guide. I assume you have a public SSH key now and your SSH is working. Open your SSH key in your favorite editor (default public key name is and is located in ~/.ssh) and copy it's content (CTRL + C). Now go to your user where you have made your git repository, since we now need to allow that SSH key to login on that user to access the GIT repository. Open this file in your favorite editor (i use nano)

nano ~/.ssh/authorized_keys

and paste the contents of in it. Be sure it is all on one line! That is important! It should look somewhat like this:

Warning: Do not copy the line below! It is an example! It will not work if you use that line!
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCboOH6AotCh4OcwJgsB4AtXzDo9Gzhl+BAHuEvnDRHNSYIURqGN4CrP+b5Bx/iLrRFOBv58TcZz1jyJ2PaGwT74kvVOe9JCCdgw4nSMBV44cy+6cTJiv6f1tw8pHRS2H6nHC9SCSAWkMX4rpiSQ0wkhjug+GtBWOXDaotIzrFwLw== username@hostname

Now you can checkout your git repo this way (change where needed. Here it's using the git username and localhost):

git clone git@localhost:my_repository.git

You should now get an SSH yes/no question. Type yes followed by enter. Then you should have your repository checked out. Since this is with SSH you also do have commit rights now. For that look at Git and Super Quick Git Guide.

GIT Daemon

Note: The git daemon only allows read access. For write access look at "Git SSH".

This will allow url's like "git clone git://localhost/my_repository.git".

Edit configuration file for git-dameon /etc/conf.d/git-daemon.conf (GIT_REPO is a place with your git projects), then start git-daemon with root privileges:

/etc/rc.d/git-daemon start

To run the git-daemon every time at boot, just append git-deamon to DAEMONS line in /etc/rc.conf file.

Clients can now simply use:

git clone git://localhost/my_repository.git