Git guide

Create

mkdir workshop

cd workshop

git init

Clone

# clone local repo

cd ~

git clone ~/git/workshop

cd ~/workshop
# clone remote repo

git clone username@host:/path/to/repo

# sample

git clone git@github.com:simongfxu/violet.git

git clone git@git.coding.net:coinxu/static.git

Add

# add a file
git add README.md

# add all files
git add *

# add current dir's files
git add .

Remove

# remove a file
git rm README.md

# remove a file but keep it in disk
git rm someConfigFile --cached

Restore

# restore a file

git checkout someConfigFile

git reset --hard

Commit

git commit -m "first commit"

# commit all modifications
# new files not added are not affected
git commit -am "first commit"

Synchronize

# connect local repo to remote repo
# you need to add a repo on github first

git remote add origin git@github.com:simongfxu/workshop.git

git pull origin master

git push origin master

# show remote name and url
git remote -v

# delete remote
git remote rm origin

Branches

# create new branch

git checkout -b develop

# back to some branch

git checkout master

# delete a branch

git branch -d hotfix_sort

# push to remote

git push origin develop

# delete remote branch

git push origin --delete hotfix_sort

Merge

git checkout feature_sort

# merge changes from develop
git merge develop

# see diff details
git diff feature_sort develop

Rebase

git checkout feature_sort

git rebase develop

# 修改冲突
git add someConfictFile

# --abrot
git rebase --continue

git checkout develop

git merge feature_sort

Diff

# see difference between two branches
git diff feature_sort develop

# see difference in commits
git log develop..
git log ..develop

Tagging

# see commit ids
git log

git tag 1.0.0 <commitID>

The End

Git guide

By simon xu

Git guide

a simple guide for git

  • 113