From Gentoo Wiki
Jump to:navigation Jump to:search

The git repositories for Gentoo developers can be found here:

Git is distributed revision control and source code management software. The goal of this article is to easily get a Git repository up and running.

Git was developed by Linus Torvalds for use on the Linux Kernel and other open source projects. According to a talk he gave for Google, he was searching for a Source Control Management (SCM) and used three criteria.

SCM must:

  1. Be distributed;
  2. Be fast;
  3. Output exactly what was put in, or an error should be printed.

Since there were no satisfactory options Linus wrote git.


USE flags

USE flags for dev-vcs/git stupid content tracker: distributed VCS designed for speed and efficiency

blksha1 Use the new optimized SHA1 implementation
cgi Install gitweb too
curl Support fetching and pushing (requires webdav too) over http:// and https:// protocols
cvs Enable CVS (Concurrent Versions System) integration
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
emacs Add support for GNU Emacs
gnome-keyring Enable support for storing passwords via gnome-keyring
gpg Pull in gnupg for signing -- without gnupg, attempts at signing will fail at runtime!
highlight GitWeb support for app-text/highlight
iconv Enable support for the iconv character set conversion library
mediawiki Support pulling and pushing from MediaWiki
mediawiki-experimental Add experimental patches for improved MediaWiki support
nls Add Native Language Support (using gettextGNU locale utilities)
pcre Add support for Perl Compatible Regular Expressions
perforce Add support for Perforce version control system (requires manual installation of Perforce client)
perl Add optional support/bindings for the Perl language
ppcsha1 Make use of a bundled routine that is optimized for the PPC arch
subversion Include git-svn for dev-vcs/subversion support
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
threads Add threads support for various packages. Usually pthreads
tk Include the 'gitk' and 'git gui' tools
webdav Adds support for push'ing to HTTP/HTTPS repositories via DAV
xinetd Add support for the xinetd super-server


Install dev-vcs/git:

root #emerge --ask dev-vcs/git


Before contributing to a project it is imperative to establish a user name and email for each user. Substitute the bracketed Larry references (brackets and everything in-between, but leave the quotes) in the next example for a personal user name and e-mail address:

user $git config --global "<>"
user $git config --global "<larry_the_cow>"


If you're the only one using your project, or if you're creating something which will be shared in a distributed way, then you should start on your workstation. If you intend to have a central server which everyone uses as the "official" server (e.g. GitHub) then it might be easier to create an empty repository there.

The next list of commands will describe how to create a repository on a workstation:

user $cd ~/src
user $mkdir hello
user $cd hello
user $touch README.TXT
user $git init

You're done. You've created a local repository. It's in the .git folder, so don't delete your hello folder unless you mean to lose everything.

Your repository is the .git folder inside the main hello folder. If you delete ~/src/hello, then your repo is gone.

Now, let's say we make some edits:

user $echo "Hello, world!" >> readme.txt

The new readme.txt file must be added (staged) before it can be included in the git repository. Use the next commands to stage the file and to make the commit:

user $git add readme.txt
user $git commit -m "Added text to readme.txt"


In this section will cover setting up a Git server for remote project management through SSH.

The Git server is only necessary if you intend to have an unauthenticated read-only server for people to get code from. See here:

If not sure then skip this section.

Initial setup

Start by creating the needed group, user, and home directory. The user uses the git-shell to prevent normal shell access.

root #groupadd git
root #useradd -m -g git -d /var/git -s /usr/bin/git-shell git

Edit /etc/conf.d/git-daemon to change user from "nobody" to "git" and start the daemon:

FILE /etc/conf.d/git-daemon

If wants to accept git push and allow access all direct, it needs to add two options --enable=receive-pack and --export-all to GITDAEMON_OPTS , ex:

FILE /etc/conf.d/git-daemon
GITDAEMON_OPTS="--syslog --export-all --enable=receive-pack --base-path=/var/git"

root #/etc/init.d/git-daemon start

SSH keys

SSH is the preferred method to handle the secure communications between client and server. For Git to work properly, you must have private/public key logins enabled and all client public keys added to /var/git/.ssh/authorized_keys.

For more information and instructions on how to enable, create, and share keys, please see the SSH - Passwordless Authentication wiki page.

this step must be completed before continuing


Create a repository and make the initial commit

On the server:

Become the git user to make sure all objects are owned by this user:

root #su git
If the following message appears,

fatal: Interactive git shell is not enabled. hint: ~/git-shell-commands should exist and have read and execute access.

temporarily set the login shell to /bin/bash (usermod -s /bin/bash git) and set it back after creating the bare repository (usermod -s /usr/bin/git-shell git). This may be also necessary when setting ssh access (see also this post).

Create a bare repository:

user $cd /var/git
user $mkdir /var/git/newproject.git
user $cd /var/git/newproject.git
user $git init --bare

On a the client station:

user $mkdir ~/newproject
user $cd ~/newproject
user $git init
user $touch test
user $git add test
user $git config --global ""
user $git config --global "larry_the_cow"
user $git commit -m 'initial commit'
user $git remote add origin
user $git push origin master
If the SSH server is not running with the default port adding the remote should look like this, with the appropriate port (in this case 59876) following the host name:

Common commands

Clone a repository:

user $git clone
The following syntaxes apply in the example above:
user $ssh://[user@]host.xz[:port]/path/to/repo.git/
user $git://host.xz[:port]/path/to/repo.git/
For more, see man git-pull(1)

Repository management via GUI

Git ships with a tk GUI. Invoke it using:

user ~/repository.git $gitk
Make sure to compile git with tk USE flag. Also make sure to be within a git repository.

Serving and managing repositories via builtin web interface

Git comes with a built-in web interface called gitweb. It can run on a variety of web servers:

  • lighttpd - No configuration necessary.
  • Apache - Some configuration necessary.
  • nginx - A small, robust, and high-performance HTTP server and reverse proxy.

In order to use gitweb be sure one of the three web servers has been installed and git has been built with the cgi USE flag.

There is a simple setup script that will create a working default configuration, start a web server (the default configuration is for lighttpd) and open the URL in a browser. Navigate to the repositories directory. Once inside type:

user ~/repository.git $git instaweb

If git instaweb opens a 404 error, enable the cgi USE flag and rebuild git.


Find out more about the options using the the built-in help output:

user ~/repository.git $git help instaweb

For additional help consider reading the contextual man page:

user ~/repository.git $man git instaweb


Per-project configuration can be set in the repositories .git/config file:

user ~/repository.git $vim .git/config

Values in this file should be specific in an ini-style format:

FILE .git/configSetting lighttpd values for instaweb in a repository's configuration
        ; local = true
        httpd = lighttpd
        port = 8080
        browser = elinks
        modulePath = /usr/lib64/lighttpd/

Adjust the values as needed. If the local = true light is uncommented (remove the ;) instaweb will only be connectable from the localhost.

See also

External resources