1. 程式人生 > >本地專案git初始化並提交遠端倉庫

本地專案git初始化並提交遠端倉庫

1、先在遠端倉庫(如github)建立專案,為了避免錯誤,不要初始化README, license, 或者gitignore檔案 .

2、開啟Terminal終端

3、切換到你的本地專案目錄

4、初始化本地倉庫

git init

5、新增檔案到本地倉庫
git add .
# Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.

6、提交檔案

git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.


7、到遠端倉庫的頁面上,複製倉庫地址 (筆者以配置好ssh,故複製ssh形式的倉庫地址)

8、新增遠端倉庫地址到本地倉庫

git remote add origin {遠端倉庫地址}
# Sets the new remote
git remote -v
# Verifies the new remote URL

9、push到遠端倉庫
git push -u origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin


完畢!