GIT Cheat Sheet

From Tmplab

Jump to: navigation, search


Basic commands (local)


git init

Adding files

git add <filename>

or to commit all files in current directory:

git add .

Committing changes

git commit -m <message>


git commit -m <message> FILE1 FILE2 FILE3 ... DIR1 DIR2 ...

or to commit all that needs:

git commit -m <message> -a

Seeing changes

git log


Adding a tag

git tag <tagname> -m "Comment about this tag"

Listing tags with comments

git tag -n

Seeing files inside repository

git ls-files
git ls-tree HEAD


git branch
git branch <NEW_BRANCH_NAME>
git checkout <NEW_BRANCH_NAME>
git commit -a
git checkout master
git merge <NEW_BRANCH_NAME>

Diff between two branches

git diff master..<NEW_BRANCH_NAME>

Remote commands

Creating an empty project on a remote machine (DH)

For first import into a GIT server for example:

mkdir -p ~/git/yourproject.git
cd ~/git/yourproject.git
git --bare init

And then on the local machine:

mkdir yourproject
cd yourproject
git init
git remote add origin ssh://
touch .gitignore
git add .
git commit -m "Initial Commit" 
git push origin master

and add this to your .git/config in your project.

[branch "master"]
  remote = origin
  merge = refs/heads/master

Push your developer commits to server

git push origin master

Get a copy of a project

git clone gitservername:proj1 proj1

Update my local copy with the server's copy

git pull

Get server's copy from a new machine

git clone ssh://[<user@>]


git “fatal: no matching remote head”

Cause: cannot fetch/clone remote empty GIT repo

mkdir autobuildrequires
cd autobuildrequires
git init
touch README
git add README
git commit -a -m "First commit."



Personal tools