$ git init
ssh密鑰可以受權遠程Git服務器識別你的計算機,只有在遠程服務器上登記了SSH密鑰才能向其提交代碼。git
# Generate the SSH key $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" # Verify the availability of SSH $ ssh -T <remote index> # example $ ssh –T git@github.com
添加(add)可以把改動保存在暫存區(stage)。github
$ git add <file> $ git add -A # add all files in this respository $ git add . # same as command "git add -A"
查看添加修改後的文件改動概況。web
$ git status
查看各文件的具體改動,包括行的添加,修改和刪除。vim
$ git diff
$ git commit $ git commit -m "<commit comment>"
$ git reset <commit id>
$ git log $ git log --graph # display log with graph
分支(branch)區別於主幹(master),它是平行於主幹的,在上面作出任何修改都不會干擾到主幹的內容,直到你把分支與主幹合併,分支和主幹的內容也隨之合併,至關於應用了分支的修改。適用於分佈式異步的開發。bash
$ git branch <branch name>
# Check the all of local branch. $ git branch # Check the all of remote and local branch. $ git branch -a *master dev debug # the branch which its name has front asterisk signal * # is current branch.
$ git checkout <branch name>
# create new local branch relate to remote branch $ git branch <local_branch> <remote>/<remote_branch> # exist local branch relate to remote branch $ git branch --set-upstream <local_branch> <remote>/<remote_branch>
遠程倉庫(remote repository)是區別於本地倉庫(local repository)的基於Git的代碼倉庫,它能夠是開發小組中統一管理項目的主機,也能夠是相似Github這樣的在線代碼倉庫。服務器
$ git clone <remote>
$ git remote # display verbose remote address with more detail. $ git remote -v
$ git remote add <remote alias> <remote url>
$ git remote rm <remote alias> # remove remote $ git remote rename <old name> <new name> # rename remote
常常用於倉庫的更新,特別是軟件的更新。ssh
$ git pull
$ git push <remote> <branch>
標籤(tag)用於管理每次提交(commit),由於每次提交都具備一個提交代號(commit id),識別起來不方便,因此能夠用標籤來表明特定的提交,使每次提交更有可讀性和便於管理,通常是用於標識版本號。異步
# add a new tag defaultly to latest commit in current branch $ git tag <tag_name> # add a new tag to specified commit $ git tag <tag_name> <commit_id> # add a tag with message $ git tag -a <tag_name> -m "<tag_message>" <commit_id>
$ git tag # show all tags $ git show <tag_name> # show specific tag detail
$ git tag -d <tag_name> # delete a specific local tag $ git push <remote> :refs/tags/<tag_name> # delete remote specific tag
$ git push <remote> <tag_name> # push specific tag to remote $ git push <remote> --tags # push all tags to remote
# format $ git config <option> <varriable> <value> # example $ git config --global user.name "your_name" $ git config --global user.email "yourname@website.com" $ git config --global color.ui true
別名,能夠自定義命令,常常用於縮略冗長的命令,達到快速輸入的效果。在用戶目錄的隱藏文件".gitconfig"中能夠修改別名分佈式
$ cd ~ $ find ".gitconfig" $ vim .gitconfig
在「[alias]下」,若是沒有,則本身定義,輸入自定義的命令別名網站
[alias] mylog = log --graph