Initialize local git repository git init
Create a library on github
Add remote push address
git remote add origin
(Note: Why can’t this origin be modified?) git@git.com/xxx/xxx.git
I think origin is equivalent to the remote library, so bind the remote branch
git branch --set-upstream-to master origin/master
Is there something wrong with my operation? The error reported is:
git branch --set-upstream-to master origin/master
fatal: branch 'origin/master' does not exist
In the end, this is how I solved it:
git push -u origin master
Thank you.
The origin/master branch did not exist before your first push
If you change the background, it may be fine. For example, after git clone, change the upstream of the new local branch to origin/master
Add
git fetch
after step 3.
The name ofgit init
初始化本地仓库,默认分支是master
.origin can be modified at will, and N remote repositories can be added. But at this time the warehouse is remote and not available locally.
After executing
git fetch
, the remote warehouse will be obtained locally, and the branch is origin/*, that is, all branches of the remote warehouse will be pulled down. The remotemaster branch corresponds to the local origin/master.
After executing
git branch --set-upstream-to master origin/master
, set the remote master branch as the local tracking branch. When executinggit pull
, you can Directly pull the remote master to the local origin/master branch and master branch. If you executegit branch --set-upstream-to master origin/master
后,将远程的 master 分支设置为本地的跟踪分支,当执行git pull
时,可以直接将远程的 master 直接拉取到本地的 origin/master 分支和 master 分支,如果执行git fetch
, only the remote master branch will be pulled to the local origin/master branch.