使用命令行的方式,首先在本地新建立一個git倉庫(若是當前項目尚未倉庫的話):
在git bash下git
1. mkdir project 2. cd project 3. git init (初始化倉庫) 4.複製項目文件到剛建立的新倉庫目錄
準備工做作好後,接着就是把本地倉庫項目推送到遠程倉庫:bash
1.git add . (將當前目錄下的文件加入到倉庫) 2.git commit -m "the first commit project" (第一次提交項目文件) 3.git remote add origin https://git.coding.net/solent/xingzuo.git 4.git push -u origin master (推送遠程倉庫)
執行第四步的時候,報錯以下:ide
To https://git.coding.net/solent/xingzuo.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://git.coding.net/solent/xingzuo.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.
報錯由於遠程倉庫與本地倉庫文件不一致,使用git pull拉下遠程代碼到本地fetch
5.git pull
接着又報以下錯誤:this
warning: no common commits remote: Counting objects: 5, done. remote: Compressing objects: 100% (4/4), done. remote: Total 5 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (5/5), done. From https://git.coding.net/solent/xingzuo * [new branch] master -> origin/master There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master
報錯緣由是沒有指定本地master和遠程origin/master的鏈接,執行git branch --set-upstream master origin/master,設置連接.net
6.git branch --set-upstream master origin/master The --set-upstream flag is deprecated and will be removed. Consider using --trac k or --set-upstream-to
Branch master set up to track remote branch master from origin.命令行
而後再執行下git pullcode
7.git pull fatal: refusing to merge unrelated histories
這回報更嚴重的致命錯誤,根據提示而後以下執行:orm
8.git pull origin master --allow-unrelated-histories From https://git.coding.net/solent/xingzuo * branch master -> FETCH_HEAD Merge made by the 'recursive' strategy. .gitignore | 46 +++++++++++++++ LICENSE | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 3 files changed, 238 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md
最後再執行推送到遠程倉庫的命令,就不會再報錯了ci
9.git push -u origin master Counting objects: 2279, done. Delta compression using up to 4 threads. Compressing objects: 100% (2227/2227), done. Writing objects: 100% (2279/2279), 46.29 MiB | 543.00 KiB/s, done. Total 2279 (delta 349), reused 0 (delta 0) To https://git.coding.net/solent/xingzuo.git 29b55c0..7c92f17 master -> master Branch master set up to track remote branch master from origin.