1、(先進入項目文件夾)通過命令 gitinit 把這個目錄變成git可以管理的倉庫
git init
2、把文件添加到本地版本庫中,使用命令git add 文件;添加到暫存區里面去,如果后面接小數點“.”,意為添加文件夾下的所有文件
git add .
3、用命令 git commit告訴Git,把文件提交到倉庫。引號內為提交說明
git commit -m 'first commit'
4、關聯到遠程庫
git remote add origin 你的遠程庫地址
如:
git remote add origin git@192.168.31.130:/srv/sample.git
如果上面步驟寫錯了:則
git remote rm origin //刪除origin
git remote add origin git@git.oschina.net:yourname/demo.git //重新添加origin
5、獲取遠程庫與本地同步合並(如果遠程庫不為空必須做這一步,否則后面的提交會失敗)
git pull --rebase origin master
6、將最新的修改推送到遠程倉庫:gitpush -u origin master
備注:origin:遠程倉庫名字;master:分支
注意:我們第一次push的時候,加上-u參數,Git就會把本地的master分支和遠程的master分支進行關聯起來,我們以后的push操作就不再需要加上-u參數了
如果出現類似下面內容:
Username for 'https://github.com': shiren1118
Password for 'https://shiren1118@github.com':
To https://github.com/shiren1118/iOS_code_agile.git
![rejected] master -> master(non-fast-forward)
error: failed to push some refs to'https://github.com/shiren1118/iOS_code_agile.git'
hint: Updates were rejected because the tip of yourcurrent branch is behind
hint: its remote counterpart. Merge the remote changes(e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push--help' for details.
則輸入命令:git push -u origin master –f即可搞定問題
如果從在git服務器所在主機上的其他賬戶獲取git服務器上面文件,則直接用
gitclone + git倉庫的路徑,即:gitclone /srv/sample.git/
來源:
https://blog.csdn.net/sinat_33366020/article/details/73732769
