[[Git]]

Git

Git is a (distributed) version control system.

Installation

aptitude install git-core git-doc

optional: install Gitolite.

Configuration

Global Config

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

git config --global core.editor vim
git config --global color.ui auto
git config --global alias.tree 'log --decorate --pretty=oneline --abbrev-commit --graph'

# see whats configured:
git config --list

# or edit the config file directly:
git config --global --edit

Per Repo Config
If you want to override the global config for just one repository you can do like so:

git config user.name "Bob Doe"
git config user.email bobdoe@example.com

# or edit the config file directly:
git config --edit

You can find your config in <repository>/.git/config

Remember to unset $GIT_AUTHOR_EMAIL and $GIT_COMMITTER_EMAIL (as well as *_NAME) because they will override your config file settings.

Bash completion
To activate bash completion it is necessary to include /etc/bash_completion.d/git

source /etc/bash_completion.d/git

or add the file to your .bashrc:

. /etc/bash_completion.d/git

Git prompt
This is a very nice feature (requires bash completion) you can tune your bash prompt:

PS1='\u@\h:\w$(__git_ps1 " [%s]")\$ '

What the placeholders mean:

\u - username
\h - hostname
\w - working directory
$(__git_ps1 " [%s]") - git infos (branch name, tag, ...)

How to Git

Initializing a repo in an existing directory:

git init

Exclude *~ files: edit $GIT_DIR/info/exclude

repodir/info/exclude
# git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
*~
*_disabled
*.disabled
*.bkup
*-dist

Ignore files when running git status:

repodir/.gitignore
# Lines that start with '#' are comments.
.gitignore
*~
*_disabled
*.disabled
*.bkup
*-dist

Add all files in current directory to git staging:

git add .

Remove a file from the staging area (or index):

git reset HEAD -- file

See status:

git status

See diffs:

# only changes that are still unstaged:
git diff
 
# already staged that will go into your next commit:
git diff --cached

Commit:

git commit
# or
git commit -m "log message"

Remove a file:

git rm file
 
# glob:
git rm \*~
 
# remove it from the staging area:
git rm --cached file

Move or rename a file:

git mv file_from file_to

Undo changes to a file:

git checkout HEAD file.sh

View logs:

git log
git log --stat
git log --pretty=format:"%h - %an, %ar : %s"
git log --pretty=format:"%h %s" --graph
git log --since=3.weeks
,
howto/git.txt · Last modified: 2015-12 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready