Git 提交程式碼到遠端倉庫5步
阿新 • • 發佈:2018-12-17
準備工作
- 安裝 Git
- 配置Git
# 區域性配置
git config user.name "遠端倉庫使用者名稱(如:github使用者名稱)"
git config user.name "遠端倉庫繫結郵箱"
# 全域性配置
git config --global user.name "遠端倉庫使用者名稱(如:github使用者名稱)"
git config --global user.name "遠端倉庫繫結郵箱"
具體操作步驟
- 初始化版本庫
git init
- 新增檔案到版本庫(只是新增到快取區),.代表新增資料夾下所有檔案
git add .
- 把新增的檔案提交到版本庫,並填寫提交備註
git commit -m "first commit"
- 把本地庫與遠端庫關聯
git remote add origin 你的遠端庫地址
- 第一次推送時需要加-u,以後提交就不需要
git push -u origin master
可能遇到的問題及解決辦法
- 問題
fatal: Authentication failed for 'https://github.com/dadeity/restful-API.git/'
- 原因 遠端倉庫的版本和本地版本不一致造成的
- 解決辦法
# 如果遠端倉庫是一個空倉庫,強制性覆蓋 git push -f # 如果遠端不是一個空倉庫,先獲取遠端倉庫版本再提交 git pull