如何把本地的代碼倉庫同步到github上

利用github存放代碼

流程

github創建倉庫 -> 本地完成編碼 -> 上傳到githubgit

操做步驟

在github上建議倉庫

圖片描述
若是選擇license的話,會在當前倉庫裏有一個LICENSE文件github

本地操做

創建reposity

mkdir helloworld
cd helloworld
git init

添加文件

git add *
git commit -m "initial version"

爲本地倉庫添加名爲origin的遠程版本庫

git remote add origin git@github.com:zhuzhzh/helloworld.git

合併遠程和本地版本

默認的話,直接上傳會遇到"non-fast-forward"以下錯誤服務器

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:zhuzhzh/helloworld.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

緣由是本地的提交不匹配遠程版本庫最新提交,若是覆蓋的話會致使服務器端數據丟失fetch

因此須要先合併本地和遠程的代碼編碼

git fetch origin
git merge origin/master

上傳到github

git push origin master
相關文章
相關標籤/搜索