I. Application Scenario: after creating a local branch, you must perform remote branch association. If no association exists, git will prompt you to add the association in the following operations. The purpose of association is to operate on the local branch: git pull and git push. You do not need to specify the remote branch in the command line.
I create a new branch in git:
Git branch my_branch
Push it:
Git push origin my_branch
Now say someone made some changes on the server and I want to pull from origin/my_branch. I do:
Git pull
But I get:
You asked me to pull without telling me which branch you
Want to merge with, and 'Branch. my_branch.merge' in
Your configuration file does not tell me, either. Please
Specify which branch you want to use on the command line and
Try again (e.g. 'git pull <repository> <refspec> ').
See Git-pull (1) for details.
If you often merge with the same branch, you may want
Use something like the following in your configuration file:
[Branch "my_branch"]
Remote = <nickname>
Merge = <remote-ref>
[Remote "<nickname>"]
Url = <URL>
Fetch = <refspec>
See Git-config (1) for details.
I learned that I can make it work:
Git Branch -- Set-upstream my_branch origin/my_branch
Note: After pushing to the remote branch, it is neither a trace of snsconnct: mater branch by default. If you do not specify the branch, you will be prompted when git pull is used.
II. Alternative:
This syntax is equivalent to using git push-u origin my_branch when the branch is submitted for the first time:
A simpler method is to replace git Branch -- Set-upstream is GIT push-u origin my_branch.
It is used when you submit your branch for the first time. It will establish a connection between the local branch and the remote branch like git Branch -- Set-upstream.
Generally, when creating a branch, We must explicitly establish this connection.
3. Similar
This be equivalent to what is automatically done when you initially clone a repository
Appendix:
The following content is added to the file after git clone. It seems that git clone is mainly a cline repository. Used for initialization. Therefore, it cannot replace -- Set-upstream.
[Core]
Repositoryformatversion = 0
Filemode = true
Logallrefupdates = true
Autocrlf = false
Bare = false
[Remote "Origin"]
Url = SSH: // root @ Hostname/path
Fetch = + refs/heads/*: refs/remotes/ORIGIN /*
[Branch "SNS"]
Remote = Origin
Merge = refs/heads/SNS
Or
# Git remote add origin SSH ://...
Now configure master to know to track
# Git config branch. master. Remote Origin
# Git config branch. master. Merge refs/heads/Master
And push
# Git push origin master
4. The final modification of the command is for the config file.
Use -- Set-upstream to track remote branches.
Config before command execution:
[Core]
Repositoryformatversion = 0
Filemode = true
Bare = false
Logallrefupdates = true
Ignorecase = true
[Remote "Origin"]
Fetch = + refs/heads/*: refs/remotes/ORIGIN /*
Url = root @****************
[Branch "master"]
Remote = Origin
Merge = refs/heads/Master
[Remote "snsconnect"]
Url = root @ app220 :/*******************
Fetch = + refs/heads/*: refs/remotes/snsconnect /*
After execution:
[Branch "SNS"]
Remote = snsconnect
Merge = refs/heads/SNS