Get started with git

There are many excellent tutorials on using git (see below). This page is just a list of git commands for my reference.

sudo apt-get install git gitk git-gui

git config --global your name
git config --global your@email
git config --list
git config --global core.editor leafpad
git config --global merge.tool vimdiff
leafpad .gitignore
git help subject

git init

git add src/*.c
git add src/*.h
git add lkr/*.lkr
git add Makefile
git rm file_to_be_removed.txt
git rm --cached file_to_be_removed_from_git_tracking.txt
git mv oldname.txt newname.txt

git commit -m 'comment'
git commit -am 'comment'
git commit -a --amend

git status
git diff
git diff --cached
git log

# remove files from repository without deleting them from the local file system
git rm --cached file_no_longer_to_be_tracked
git rm --cached -r directory_no_longer_to_be_tracked
git rm --cached `git ls-files -i -X .gitignore`

# show branches in tree format
git log --graph --all --decorate --oneline

# diff between tips of two branches
git diff branch_1..branch_2
git diff branch_2..branch_1
git diff branch_1...branch_2


git clone git:// mygrit

ssh username@server
# on remote gitserver
mkdir /opt/git/project_directory
cd /opt/git/project_directory
git init --bare --shared

# on local machine
git clone ssh://username@gitserver/opt/git/project_directory local_directory

git remote add origin git@gitserver:/opt/git/project.git

git fetch origin
git merge origin/master
git push origin master

# and many many more possibilities...

A short selection of reference links:

Leave a Reply

Your email address will not be published. Required fields are marked *