Git Basics

Last modified: 
Thursday, July 2nd, 2015

Config Settings

Show current configuration

git config --list

Set a global ignore file

git config --global core.excludesfile '~/.gitignore'

See also

Enable color

git config --global --add color.ui true

Set user name and email

git config --global "Your Name"
git config --global

Set text editor

git config --global core.editor "vim"

Clone a Gitolite managed repository

Using ssh:// to clone repositories managed by Gitolite may prevent a lot of errors when pushing changes later.

git clone ssh://gitolite@host/gitolite-admin.git

Deleting files (rm)

Remove all deleted files

git rm $(git ls-files --deleted)

This may not work with large files lists.

Reverting changes with RESET

Force a reversion back to HEAD

git reset --hard HEAD

Branching and merging

Create new branch called experimental.

git branch experimental

Checkout the new branch.

git checkout experimental

Make and commit some edits, then switch back to master branch.

git commit -a -m "Commit message"
git checkout master

Merge experimental branch into current branch (*master).

git merge experimental

Delete a branch.

git branch -d experimental


git branch -D experimental

Tags and tagging

git tag -a [name]

Create a Centralized Repossitory

Create a bare repository in the central location.

git init --bare

Clone the bare repository.

git clone ssh://username@hostname//path/to/repos

Change to the new directory, add some files, commit the changes, then push them to the origin repository.

git add .
git commit -m "Initial import"
git push origin master

Archive (Export)

The following will create an archive of branch ''master'' output as a zip archive named '''' which will decompress into a folder named ''archive''.

git archive --format zip --output --prefix=archive/ master


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.