Git Getting Started

To work locally with Git repositories, use the following configuration examples and command line instructions.

Configure the .gitconfig file

The ~/.gitconfig file is a configuration file which controls how Git interacts between the server and your local setup.

For Git, you can set this up in your home directory and it will be applied to all repositories. Use the following example configuration to set up your file, and put your own information into the relevant sections.

For more detailed information, and a full rundown of all configuration options, see the gitconfig documentation.

[user]
name = username
email = user@mail.com

[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore

[rerere]
enabled = 1
autoupdate = 1

[push]
default = matching

[color]
ui = auto

[color "branch"]
current = yellow bold
local = green bold
remote = cyan bold

[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
whitespace = red reverse

[color "status"]
added = green bold
changed = yellow bold
untracked = red bold

[diff]
tool = vimdiff

[difftool]
prompt = false

[alias]
a = add --all
ai = add -i
ap = apply
as = apply --stat
ac = apply --check

Configure the .gitignore file

The ~path/to/repo/.gitignore file is a configuration file that tells Git to ignore certain files and not commit them to the repository. Files such as build files, or editor tracking files are usually not committed to a repository.

Create the .gitignore file in your repository and configure it using the following example to ignore the files you do not wish to be added to version control. For more information, see the gitignore documentation

syntax: glob
result
www
*_build/*
*result/*
*.pyc
*.pyo
*.idea
.DS_Store

Using basic Git commands

The following commands will get you through the basics of using Git on the command line. For a full run through of all Git commands and options, see the Git Command Line Reference Guide

  • git init - create a new git repository.
  • git clone URI - Clone a repository to your local machine.
  • git add <filename> - Add a file to staging.
  • git commit -m "Commit message" - Commit files in staging to the repository
  • git push origin master - Push changes to the master branch.
  • git checkout -b feature_name - Create a new branch named feature_name and switch to it using.
  • git checkout master - Switch back to the master branch.
  • git branch -d feature_name - Delete the branced named feature_name.
  • git pull - Pull changes on the server into the local repository.
  • git merge <branch> - Merge another branch into your active branch.