Re: connecting the local main branch to the remote origin/main without pushing
- From
- crstml@libero.it <crstml@libero.it>
- Date
- Dec 29, 2024, 10:01 UTC
- Message-ID
- <5dfb85a8-2e26-92f8-e3f9-5e3fb89ca43a@libero.it>
- In-Reply-To
- <87h66nk9uy.fsf@igel.home>
Andreas Schwab wrote:
Show 12 quoted lines
> On Dez 28 2024, crstml@libero.it wrote: > >> My question is: >> Is it possible when applying the method 2 to have (without pushing) >> the local main branch connected to the remote origin/main branch as >> in the case of method 1 which by cloning connects these branches. > > You can establish the effect by setting two config entries: > > $ git config branch.main.remote origin > $ git config branch.main.merge refs/heads/main >
Indeed.
By making a diff between a folder containing a cloned empty repository (method 1) and an empty folder in which "git init" and "git remote" were run (method 2) the only difference is in the .git/config file. In the cloned version the file contains the following section:
[branch "main"]
remote = origin
merge = refs/heads/mainThese commands add exactly this section to the file.
"git branch -u" does exactly the same thing when connecting a local branch to an existing remote branch. It adds this section. "git push ---set-upstream" also does the same thing.
It would be nice if "git branch -u" would work for an empty remote repository and allow us to set the upstream branch.
Cristian