* connecting the local main branch to the remote origin/main without pushing
@ 2024-12-28 15:47 crstml
2024-12-28 16:11 ` rsbecker
2024-12-28 17:15 ` Andreas Schwab
0 siblings, 2 replies; 10+ messages in thread
From: crstml @ 2024-12-28 15:47 UTC (permalink / raw)
To: git
Hello all
I would like to put a set of files under version control and I
have some issues with the workflow. Let me explain:
First I create the bare repository with the command:
git init --bare -b main ~/rps/project-x.git
Then I can proceed in one of the following ways:
---- Method 1 ----
By first cloning the remote repository locally and next
putting the files under version control. All running the
following commands:
1 cd ~/projects;
2 git clone ~/rps/project-x.git project-x
3 cp ~/my-existing-project-x-files/* project-x
4 cd project-x
5 git add .
6 git commit -m "fc"
7 git push origin
8 rm -rf ~/my-existing-project-x-files # clean your home folder
---- Method 2 ----
By putting the existing files under version control and next
adding the remote. Running the following commands:
1 cd ~/projects/project-x
2 git init -b main
3 git add .
4 git commit -m "fc"
5 git remote add origin ~/rps/project-x.git
6 git push --set-upstream origin main
Let me discuss both these methods:
Method 1:
Everything works but the cp statement may be problematic. If
you have hidden files (starting with .) or if you want to
preserve the file permissions and owenership, the invokation
of the cp command is trickier.
After you copy the files all the next statements work well.
The main branch in the cloned repository is connected to the
upstream origin/main branch and "git push" will work.
There is one more small problem with this workflow: the
statement 8 is ugly.
Method 2
Everything is very clean (apparently). We don't have to think
to file permissions, hidden files, tricky cp invocations and
there is no need to clean your home folder at the end. We are
interested to put files under version control, so we focus only
the version control system.
The problem with this workflow (from my point of view) is the
statement 6. This statement makes two things which is contrary
to the UNIX philosophy: programs that do one thing and do it well.
1) The command connects the local main branch to the
remote origin/main branch.
2) Pushes the files to the remote.
From my point of view instead of executing the statement 6 I would
like to execute the following two statements that I will number
here as 6.1 and 6.2:
6.1 # To connect the main branch to origin/main
#
git branch -u origin/main main
6.2 # To push to the remote.
#
git push origin
However, the statement 6.1 does not work. Git prints the following
message.
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
hint: Disable this message with "git config advice.setUpstreamFailure false"
The end solution it suggests to use with "git push -u" which
is the same as the statement on line 6 that I would like to
avoid. I would add that by issuing a "git fecth" before 6.1
would not bring the remote branch origin/main in the local
repository.
The core of the problem is that the local branch main is not connected
to the origin/main branch.
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.
Thank you
Cristian
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: connecting the local main branch to the remote origin/main without pushing
2024-12-28 15:47 connecting the local main branch to the remote origin/main without pushing crstml
@ 2024-12-28 16:11 ` rsbecker
2024-12-29 9:01 ` crstml
2024-12-28 17:15 ` Andreas Schwab
1 sibling, 1 reply; 10+ messages in thread
From: rsbecker @ 2024-12-28 16:11 UTC (permalink / raw)
To: crstml, git
On December 28, 2024 10:47 AM crstml@libero.it wrote:
>I would like to put a set of files under version control and I have some issues with
>the workflow. Let me explain:
>
>First I create the bare repository with the command:
>
> git init --bare -b main ~/rps/project-x.git
>
>Then I can proceed in one of the following ways:
>
>
>---- Method 1 ----
>
> By first cloning the remote repository locally and next
> putting the files under version control. All running the
> following commands:
>
> 1 cd ~/projects;
> 2 git clone ~/rps/project-x.git project-x
> 3 cp ~/my-existing-project-x-files/* project-x
> 4 cd project-x
> 5 git add .
> 6 git commit -m "fc"
> 7 git push origin
> 8 rm -rf ~/my-existing-project-x-files # clean your home folder
>
>---- Method 2 ----
>
> By putting the existing files under version control and next
> adding the remote. Running the following commands:
>
> 1 cd ~/projects/project-x
> 2 git init -b main
> 3 git add .
> 4 git commit -m "fc"
> 5 git remote add origin ~/rps/project-x.git
> 6 git push --set-upstream origin main
>
>
>Let me discuss both these methods:
>
>Method 1:
>
> Everything works but the cp statement may be problematic. If
> you have hidden files (starting with .) or if you want to
> preserve the file permissions and owenership, the invokation
> of the cp command is trickier.
>
> After you copy the files all the next statements work well.
> The main branch in the cloned repository is connected to the
> upstream origin/main branch and "git push" will work.
>
> There is one more small problem with this workflow: the
> statement 8 is ugly.
>
>
>
>Method 2
>
> Everything is very clean (apparently). We don't have to think
> to file permissions, hidden files, tricky cp invocations and
> there is no need to clean your home folder at the end. We are
> interested to put files under version control, so we focus only
> the version control system.
>
>
> The problem with this workflow (from my point of view) is the
> statement 6. This statement makes two things which is contrary
> to the UNIX philosophy: programs that do one thing and do it well.
>
> 1) The command connects the local main branch to the
> remote origin/main branch.
>
> 2) Pushes the files to the remote.
>
> From my point of view instead of executing the statement 6 I would
> like to execute the following two statements that I will number
> here as 6.1 and 6.2:
>
> 6.1 # To connect the main branch to origin/main
> #
> git branch -u origin/main main
>
> 6.2 # To push to the remote.
> #
> git push origin
>
> However, the statement 6.1 does not work. Git prints the following
> message.
>
> hint: If you are planning on basing your work on an upstream
> hint: branch that already exists at the remote, you may need to
> hint: run "git fetch" to retrieve it.
> hint:
> hint: If you are planning to push out a new local branch that
> hint: will track its remote counterpart, you may want to use
> hint: "git push -u" to set the upstream config as you push.
> hint: Disable this message with "git config advice.setUpstreamFailure false"
>
> The end solution it suggests to use with "git push -u" which
> is the same as the statement on line 6 that I would like to
> avoid. I would add that by issuing a "git fecth" before 6.1
> would not bring the remote branch origin/main in the local
> repository.
>
> The core of the problem is that the local branch main is not connected
> to the origin/main branch.
>
>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.
I think method 2 is failing for you because you do not have origin/main in your
local repository. That requires a git fetch. Git fetch will not overwrite your
working area, but is needed so that tracking can occur with an existing
remote branch.
The reason git push -u works is that the resolution of your branch tracking
can be worked out by git as part of the push, where the remote reference
is known. Without that, the git branch -u does not work (no reference).
So do the git fetch as 5.9 in Method 2, then 6.1 should work, assuming origin/main
exists in your remote. This downloads the clone history without modifying
your work area, so it should be fine.
--Randall
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: connecting the local main branch to the remote origin/main without pushing
2024-12-28 15:47 connecting the local main branch to the remote origin/main without pushing crstml
2024-12-28 16:11 ` rsbecker
@ 2024-12-28 17:15 ` Andreas Schwab
2024-12-28 17:20 ` Junio C Hamano
` (3 more replies)
1 sibling, 4 replies; 10+ messages in thread
From: Andreas Schwab @ 2024-12-28 17:15 UTC (permalink / raw)
To: crstml; +Cc: git
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
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: connecting the local main branch to the remote origin/main without pushing
2024-12-28 17:15 ` Andreas Schwab
@ 2024-12-28 17:20 ` Junio C Hamano
2024-12-28 19:08 ` Jeff King
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2024-12-28 17:20 UTC (permalink / raw)
To: Andreas Schwab; +Cc: crstml, git
Andreas Schwab <schwab@linux-m68k.org> writes:
> 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
Perfect ;-) Thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: connecting the local main branch to the remote origin/main without pushing
2024-12-28 17:15 ` Andreas Schwab
2024-12-28 17:20 ` Junio C Hamano
@ 2024-12-28 19:08 ` Jeff King
2024-12-28 19:39 ` Andreas Schwab
2024-12-29 10:01 ` crstml
2024-12-29 10:03 ` crstml
3 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2024-12-28 19:08 UTC (permalink / raw)
To: Andreas Schwab; +Cc: crstml, git
On Sat, Dec 28, 2024 at 06:15:01PM +0100, Andreas Schwab wrote:
> 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
Also:
git branch --set-upstream-to=origin/main main
(sets the same config variables, but maybe a little more ergonomic).
-Peff
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: connecting the local main branch to the remote origin/main without pushing
2024-12-28 19:08 ` Jeff King
@ 2024-12-28 19:39 ` Andreas Schwab
0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2024-12-28 19:39 UTC (permalink / raw)
To: Jeff King; +Cc: crstml, git
On Dez 28 2024, Jeff King wrote:
> On Sat, Dec 28, 2024 at 06:15:01PM +0100, Andreas Schwab wrote:
>
>> 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
>
> Also:
>
> git branch --set-upstream-to=origin/main main
>
> (sets the same config variables, but maybe a little more ergonomic).
That does not work if origin/main does not exist yet.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: connecting the local main branch to the remote origin/main without pushing
2024-12-28 16:11 ` rsbecker
@ 2024-12-29 9:01 ` crstml
0 siblings, 0 replies; 10+ messages in thread
From: crstml @ 2024-12-29 9:01 UTC (permalink / raw)
To: rsbecker, git
rsbecker@nexbridge.com wrote:
> On December 28, 2024 10:47 AM crstml@libero.it wrote:
>> I would like to put a set of files under version control and I have some issues with
>> the workflow. Let me explain:
>>
>> First I create the bare repository with the command:
>>
>> git init --bare -b main ~/rps/project-x.git
>>
>> Then I can proceed in one of the following ways:
>>
>>
>> ---- Method 1 ----
>>
>> By first cloning the remote repository locally and next
>> putting the files under version control. All running the
>> following commands:
>>
>> 1 cd ~/projects;
>> 2 git clone ~/rps/project-x.git project-x
>> 3 cp ~/my-existing-project-x-files/* project-x
>> 4 cd project-x
>> 5 git add .
>> 6 git commit -m "fc"
>> 7 git push origin
>> 8 rm -rf ~/my-existing-project-x-files # clean your home folder
>>
>> ---- Method 2 ----
>>
>> By putting the existing files under version control and next
>> adding the remote. Running the following commands:
>>
>> 1 cd ~/projects/project-x
>> 2 git init -b main
>> 3 git add .
>> 4 git commit -m "fc"
>> 5 git remote add origin ~/rps/project-x.git
>> 6 git push --set-upstream origin main
>>
>>
>> Let me discuss both these methods:
>>
>> Method 1:
>>
>> Everything works but the cp statement may be problematic. If
>> you have hidden files (starting with .) or if you want to
>> preserve the file permissions and owenership, the invokation
>> of the cp command is trickier.
>>
>> After you copy the files all the next statements work well.
>> The main branch in the cloned repository is connected to the
>> upstream origin/main branch and "git push" will work.
>>
>> There is one more small problem with this workflow: the
>> statement 8 is ugly.
>>
>>
>>
>> Method 2
>>
>> Everything is very clean (apparently). We don't have to think
>> to file permissions, hidden files, tricky cp invocations and
>> there is no need to clean your home folder at the end. We are
>> interested to put files under version control, so we focus only
>> the version control system.
>>
>>
>> The problem with this workflow (from my point of view) is the
>> statement 6. This statement makes two things which is contrary
>> to the UNIX philosophy: programs that do one thing and do it well.
>>
>> 1) The command connects the local main branch to the
>> remote origin/main branch.
>>
>> 2) Pushes the files to the remote.
>>
>> From my point of view instead of executing the statement 6 I would
>> like to execute the following two statements that I will number
>> here as 6.1 and 6.2:
>>
>> 6.1 # To connect the main branch to origin/main
>> #
>> git branch -u origin/main main
>>
>> 6.2 # To push to the remote.
>> #
>> git push origin
>>
>> However, the statement 6.1 does not work. Git prints the following
>> message.
>>
>> hint: If you are planning on basing your work on an upstream
>> hint: branch that already exists at the remote, you may need to
>> hint: run "git fetch" to retrieve it.
>> hint:
>> hint: If you are planning to push out a new local branch that
>> hint: will track its remote counterpart, you may want to use
>> hint: "git push -u" to set the upstream config as you push.
>> hint: Disable this message with "git config advice.setUpstreamFailure false"
>>
>> The end solution it suggests to use with "git push -u" which
>> is the same as the statement on line 6 that I would like to
>> avoid. I would add that by issuing a "git fecth" before 6.1
>> would not bring the remote branch origin/main in the local
>> repository.
>>
>> The core of the problem is that the local branch main is not connected
>> to the origin/main branch.
>>
>> 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.
>
> I think method 2 is failing for you because you do not have origin/main in your
> local repository. That requires a git fetch. Git fetch will not overwrite your
> working area, but is needed so that tracking can occur with an existing
> remote branch.
>
> The reason git push -u works is that the resolution of your branch tracking
> can be worked out by git as part of the push, where the remote reference
> is known. Without that, the git branch -u does not work (no reference).
>
> So do the git fetch as 5.9 in Method 2, then 6.1 should work, assuming origin/main
> exists in your remote. This downloads the clone history without modifying
> your work area, so it should be fine.
>
Good observations.
I've imagined that the commit history and the configuration of the remote
repository is necessary to be known to the local git and I've also performed
a test in which I've executed a "git fetch" before 6.1 (without "git fetch"
no information from the remote repository exists locally).
Unfortunately it did not work and git printed out the following message:
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
hint: Disable this message with "git config advice.setUpstreamFailure false"
> --Randall
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: connecting the local main branch to the remote origin/main without pushing
2024-12-28 17:15 ` Andreas Schwab
2024-12-28 17:20 ` Junio C Hamano
2024-12-28 19:08 ` Jeff King
@ 2024-12-29 10:01 ` crstml
2024-12-29 14:39 ` rsbecker
2024-12-29 10:03 ` crstml
3 siblings, 1 reply; 10+ messages in thread
From: crstml @ 2024-12-29 10:01 UTC (permalink / raw)
To: Andreas Schwab; +Cc: git
Andreas Schwab wrote:
> 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/main
These 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: connecting the local main branch to the remote origin/main without pushing
2024-12-28 17:15 ` Andreas Schwab
` (2 preceding siblings ...)
2024-12-29 10:01 ` crstml
@ 2024-12-29 10:03 ` crstml
3 siblings, 0 replies; 10+ messages in thread
From: crstml @ 2024-12-29 10:03 UTC (permalink / raw)
To: Andreas Schwab; +Cc: git
Andreas Schwab wrote:
> 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
>
Excelent. Thank you for the info.
Cristian
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: connecting the local main branch to the remote origin/main without pushing
2024-12-29 10:01 ` crstml
@ 2024-12-29 14:39 ` rsbecker
0 siblings, 0 replies; 10+ messages in thread
From: rsbecker @ 2024-12-29 14:39 UTC (permalink / raw)
To: crstml, 'Andreas Schwab'; +Cc: git
On December 29, 2024 5:02 AM, crstml@libero.it wrote:
>Andreas Schwab wrote:
>> 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/main
>
>These 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.
It might be a useful contribution to make git branch --force -u understand this.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-12-29 14:40 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-28 15:47 connecting the local main branch to the remote origin/main without pushing crstml
2024-12-28 16:11 ` rsbecker
2024-12-29 9:01 ` crstml
2024-12-28 17:15 ` Andreas Schwab
2024-12-28 17:20 ` Junio C Hamano
2024-12-28 19:08 ` Jeff King
2024-12-28 19:39 ` Andreas Schwab
2024-12-29 10:01 ` crstml
2024-12-29 14:39 ` rsbecker
2024-12-29 10:03 ` crstml
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).