Git Basic Operations


Before Git

Version control : In computer software engineering, revision control is any kind of practice that tracks and provides control over changes to source code. Software developers sometimes use revision control software to maintain documentation and configuration files as well as source code.

Git: a free and open source distributed version control system.

Subversion(SVN): a centralized reversion control system.

Basic Concepts

Installation & Configuration


Basic Operations

Create and Commit
git init	# ls -ah  to see the .git
git add <filename>
git add .
git commit -m 'descriptions'
git commit -am 'descriptions' 			#  combine add and commit
git commit -a -m 'descriptions'
git clone <repo>
git clone <repo> <directory>
Check commits
git status
git status --short or git status -s
git diff
git diff --staged 
git diff <branch1> <branch2>
Log & history
git log
git log --oneline #  a line
#  -- reserve --graph --author=XXX  --color
git log --graph --oneline --decorate --all
Delete & Move files
git rm <filename> # remove from INDEX and WORKDIR
git rm --cached <filename>  # only remove from INDEX
git mv <filename> <newname> # rename
git mv <dir 1> <dir new> # move files
Revert (Roll-back)
git log 
git reflog
git reset --hard commit_id

Remote Repository

Here, specially for GitHub.

Authenticating with GitHub from Git
# generate key
ssh-keygen -t rsa -c ""
# copy key and add it to github
xclip -sel c ~/.ssh/
clip < ~/.ssh/
# test it
ssh -T
# Checking for existing SSH keys
ls -al ~/.ssh
Clone Remotes
git clone # http
git clone ZhenZHAO/ #ssh
git remote
git remote -v
git remote show <remote-name> # eg. git remote show origin
git remote rename <remote-name1> <remote-name2>
Add Remotes
git remote add <RepoName> #default:origin
Fetch and pull
# it doesn’t automatically merge it with any of your work or modify what you’re currently working on
git fetch [remote-name] # usually, origin
# pull: automatically fetch and then merge
git pull
Push to Remotes
# first
git push -u origin master
# later
git push <remote-name> <branchname>

Branch Management

Create and fast-forward merge
git branch # view all branch
git branch <branchname> # create
git checkout <branchname> # switch branch
git checkout -b <branchname> #create and switch
# merge, first go back to master, then
git merge <branchname>
git branch -d <branchname> # delete
Branch Hints
Push, Pull


git tag
git tag -l 'v1.*'
git tag -a <tagname> -m "tag discriptions"
git tag -a <tagname> commit_id
git show v1.0.1
git push origin [tagname]

Command Details

Difference between git reset and git checkout : Git Tools - Reset Demystified chinese

Local Server

To be added.


To be added.

Table of Contents