Git workflow
2021-02-19 11:03 git
Summary of this post
A note for 2 types of the git workflow:
- Create a GitHub repository first, then clone it to local to work
- Work on local first, then create a GitHub repository to push local work to it
先git clone一個空的 repository 再開始本機作業會省事一點。
Environment
git: 2.30.0.windows.2
os: Windows_NT 10.0.18363 win32 x64
Workflow: git clone first
- Create a repository on GitHub
- Copy the repository URL
https://github.com/<username>/<repository-name>.git - Launch cmd.exe, move to the preferred location, run
git clone <repository URL> - Move to the folder by
cd <repository-name> - Complete the work in local folder, run
git add .andgit commit - Run
git pushto push the local work to the GitHub repository
Note: no need to config the remote and branch manually, git clone will take care these.
先git clone一個空的 repository 可以省略手動設定 remote 跟 branch 的步驟。
Workflow: local work first
- Complete the work locally
- Create a repository on GitHub
- Run
git initin the local working folder - Run the following command to add remote URL:
git remote add <short-name-for-repository> <url-for-repository>For example:git remote add origin https://github.com/tzynwang/hello.git - Run
git add .andgit commit - Run
git push --set-upstream origin masterto push local content to GitHub repository
Note: need to config git remote and git push --set-upstream manually
如果先在本機執行作業前沒有先git clone一個空的 repository,那麼git init後必須手動執行git remote add,第一次git push時也須加上--set-upstream origin master