Table of Contents

GIT CheatSheet

See diff between local commits and remote master

git diff master origin/master

Pull from origin and overwrite local changes

git reset --hard; git pull -Xtheirs

Useful if you have local changes that you do no longer need.

Mark file as 'unchanged'

This will ignore the file on all commits using the -a argument.

git update-index --assume-unchanged [file]

To include the file in commites again use:

git update-index --no-assume-unchanged [file]

This is particularly handy when making local changes to a config file that must not enter the central repository.

List current status (including changes) in repo

git status

List files in repo

git ls-files

List deleted files in repo

git ls-files -d

Undelete file

git checkout filename

Undelete all deleted files

git ls-files -d | xargs git checkout --

Mark conflict as resolved

filename will have merge conflicts marked in the same way used in CVS.

git add filename

marks the conflict as resolved.

Turn off pager

git --no-pager [command]

Run

alias git='git --no-pager'

to disable it on all commands in the current shell. Alternatively set core.pager = in .gitconfig (it is set to the empty string.) to disable it entirely for that user.

Tags

Create

# create tag locally:
git tag -a v1.4 -m 'version 1.4'

# push tag to server:
git push –-tags

List

All:

git tag

Or filtered:

git tag -l v1.*

Show

git show v1.4

Delete

# delete tag locally:
git tag -d v1.0

# push tag deletion to origin:
git push origin :refs/tags/v1.0

Branches

List branches

git branch

Create branch

Create and switch to:

git checkout -b [branchname]

Just create:

git branch [branchname]

Push to server:

git push -u origin [branchname]

Switch to branch

git checkout [branchname]

Delete branch

git branch -d branchname
git push origin --delete branchname

Fecth branches from server

git fetch --all

CVS 2 GIT

git cvsimport -k -i -d server:/path/to/CVSHOME -C git_reponame cvs_reponame

The resulting git_reponame directory now contains the .git folder which can be moved to a server location for shared access. Run git update-server-info in the new server folder in order to make it shareable.

Branching/Merging

From: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

Creating a new repository

As root:
mkdir /home/git/repos/[reponame].git
cd /home/git/repos/[reponame].git
git --bare init
git update-server-info
chown -R apache:apache /home/git/repos/[repomame].git

Now clone the project on a client, add some files and commit them. When pushing them for the first time use the following command:

git push origin master

NOTE: If this is done by the usual 'git push' command, a 'No refs in common and none specified; doing nothing.' error will be issued.

Set up repository mirror

From: https://help.github.com/articles/duplicating-a-repository/

# Create a bare clone of the repository.
git clone --bare https://github.com/exampleuser/old-repository.git

# Mirror-push to the new repository.
cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git

Move single directory to its own repository

http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475

Replace email address in commits and tags

https://help.github.com/articles/changing-author-info/

NOTE: The way the push command is performed is important in order to overwrite bot commits and tags.