Git cheat-sheat

Table of Contents

Note: Git will "remember" the source repository URL when cloning a repository, and referring to "origin" will point to this original source. So "origin" refers to SOURCE repository (e.g. user@server:repository) .

Commands

Clone the remote repository

git clone user@server:repository

Add untracked files (to your staged area):

git add <FILE_NAME>

Commit changes from staging area to (your own local) repository:

git commit <FILE_NAME> -m "This is the log message."

Commit ALL changed files (with verbose)

git commit -a -v -m "This is the log message."

Push changes from your repository to remote repository:

git push origin

The remote repository will be the source that your repository was cloned from or an other remote repository that you've configured 'origin' to point to.

Tag current committed version (of all files).

git tag -a <TAG_NAME>

A tag acts like a named commit.

Tag earlier commit:

git -tag -a <TAG_NAME> <REVISION-HASH>

Push tag to SOURCE repository

git push origin <TAG_NAME>

Checkout tag (run git clone first, then checkout tag):

git checkout <TAG_NAME>

Update tags/branched/etc from remote

git fetch

Which tag is checked out (–tags needed for lightweight tags)

git describe --tags

Commit log (add –stat for nice graph):

git log

Push ALL tags to remote

git push --tags

Delete a tag

git tag -d <TAG_NAME>
git push origin :refs/tags/<TAG_NAME>

First push

The first git push always requires you to specify the branch you want to push.

git push origin master

Show URL of 'origin'

git remote show origin

Create a 'bare' repository

A 'bare' Git repository does not contain the regular source files - only the Git data. You'll have to clone it somewhere to edit/add files in the repo.

git --bare init <repository>

Gitolite

Gitolite allows you to keep a central repository server with a list of admin users allowed to create new projects. All user authentication is done using SSH public keys.

  • Grant users access by adding their public key to the keys/ folder in the gitolite-admin repo.
  • Grant them read or write access to each repository by editing the gitolite.conf file in the gitolite-admin repo.

Installing

Copy your id_rsa.pub to the new Git server (remember to rename it to <YOUR-USERNAME>.pub).

Then run on server:

sudo aptitude install gitolite3
sudo dpkg-reconfigure gitolite3

First two defaults are probably OK - the third and last option prompts for the .pub file you uploaded.

Administrating the repositories

Clone the admin repo with:

git clone gitolite3@<HOSTNAME>:gitolite-admin

Then edit the conf file to add new repositories.

emacs config/gitolite.conf

Format:

@staff      =   alice bob carol

repo foo                 
    RW+         =   alice
    RW          =   bob  
    R           =   @staff

Commit and push your changes:

git commit -m 'Added foo repo, rw+: alice, rw: bob, R: @staff'
git push

List accessible repositories on Gitolite server

ssh gitolite3@git.domain.tld info

Author: Rói á Torkilsheyggi

Created: 2016-07-27 Wed 20:41

Emacs 24.5.1 (Org mode 8.2.10)

Validate