git命令整理(個人向)

工作區

    一個你存放代碼的目錄相當於一個工作區

版本庫

    在你的工作區中創建一個新倉庫

git init

//將文件添加到暫存區(stage)
git add <file>
//將所有文件添加到暫存區(stage)
git add .

 

//提交到HEAD
git commit -m "代碼提交信息"
//添加遠程倉庫地址
git remote add origin <url>
//提交到遠程倉庫,master是你要推送的分支
git push origin master

若出現此類錯誤

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/.../.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

則可輸入 

//強制更新推送
git push --force <url>

 分支

//列出分支
git branch
//列出分支(本地和遠程倉庫)
git branch -a
//建立分支
git branch <branch>
//切換分支
git checkout <branch>
//刪除分支
git branch -d <branch> 
//合併分支
git merge <branch>
//推送分支
git push origin <branch>
//刪除遠程分支
git push origin --delete <branchName>

其他命令

//刪除遠程倉庫文件
git rm -r --cached <file>
git commit -m "註釋"
git push origin master

//添加遠程倉庫地址
git remote add origin <url>
//修改遠程倉庫地址
git remote set-url origin <url>
//刪除遠程倉庫地址
git remote rm origin

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章