All of lore.kernel.org
 help / color / mirror / Atom feed
* Git oddities with case of branch names on Windows
       [not found] <CAAR1xzQwhbHNFFyTJQvkSVLJyJz_Gj5_FQ_udJrjM=ou+3GB3w@mail.gmail.com>
@ 2023-02-15 13:28 ` Patakreyp Chandler
  2023-02-15 16:53   ` Torsten Bögershausen
  0 siblings, 1 reply; 3+ messages in thread
From: Patakreyp Chandler @ 2023-02-15 13:28 UTC (permalink / raw)
  To: git

Hello,

Here is a scenario for some oddities (bugs?) for case of branch names
(at least with git version 2.37.3.windows.1).

First, we have created an empty git repository on our internal GitHub
server and we clone this repository
    $ git clone git@github.mycompany.com:ID123456/test_branches.git ppppppp
    Cloning into 'ppppppp'...
    warning: You appear to have cloned an empty repository.

Then we create an object in this repository on main branch, we add,
commit and push it:
    $ cd ppppppp/
    $ echo foo > foo
    $ git add foo
     warning: in the working copy of 'foo', LF will be replaced by
CRLF the next time Git touches it
    $ git commit -m 'foo'
     [main (root-commit) 51789b0] foo
     1 file changed, 1 insertion(+)
     create mode 100644 foo
    $ git push
     Enumerating objects: 3, done.
     Counting objects: 100% (3/3), done.
     Writing objects: 100% (3/3), 869 bytes | 869.00 KiB/s, done.
     Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
     To github.mycompany.com:ID123456/test_branches.git
     * [new branch]      main -> main

We create a new branch in this repository and switch to it:
    $ git checkout -b gggg
     Switched to a new branch 'gggg'

We create an object in this repository on the new branch, we add,
commit and push it:
    $ echo bar > bar
    $ git add bar
     warning: in the working copy of 'bar', LF will be replaced by
CRLF the next time Git touches it
    $ git commit -m 'bar'
     [gggg 8f2fdd0] bar
     1 file changed, 1 insertion(+)
     create mode 100644 bar
    $ git push --set-upstream origin gggg
     Enumerating objects: 4, done.
     Counting objects: 100% (4/4), done.
     Delta compression using up to 4 threads
     Compressing objects: 100% (2/2), done.
     Writing objects: 100% (3/3), 929 bytes | 929.00 KiB/s, done.
     Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
     remote:
     remote: Create a pull request for 'gggg' on GitHub by visiting:
     remote:
https://github.mycompany.com/ID123456/test_branches/pull/new/gggg
     remote:
     To github.mycompany.com:ID123456/test_branches.git
     * [new branch]      gggg -> gggg
     branch 'gggg' set up to track 'origin/gggg'.

If we look at the local branches, everything is normal:
    $ git branch -vv
     * gggg 8f2fdd0 [origin/gggg] bar
       main 51789b0 [origin/main] foo

Now we “switch” to the exact same branch but with a typo (here, 'GGGG'
instead of 'gggg') in the case of branch name (this does not work with
git on Linux "error: pathspec 'GGGG' did not match any file(s) known
to git."):
    $ git checkout GGGG
     Switched to branch 'GGGG'

We create an object in this repository on the (not really) new branch
(with faulty case name), we add, commit and (try to) push it:
    $ echo foobar > foobar
    $ git add foobar
     warning: in the working copy of 'foobar', LF will be replaced by
CRLF the next time Git touches it
    $ git commit -m 'foobar'
     [GGGG 2ed967b] foobar
     1 file changed, 1 insertion(+)
     create mode 100644 foobar
    $ git push
    fatal: The current branch GGGG has no upstream branch.
    To push the current branch and set the remote as upstream, use
            git push --set-upstream origin GGGG
    To have this happen automatically for branches without a tracking
    upstream, see 'push.autoSetupRemote' in 'git help config'.

Pushing actually fails because git says "The current branch GGGG has
no upstream branch ", and if we check this badly cased branch ("GGGG")
has no upstream tracked branch, but is still the same correctly cased
branch ("gggg"):
    $ git branch -vv
     * GGGG 2ed967b foobar
        main 51789b0 [origin/main] foo
    $ git branch -a
     * GGGG
       main
       remotes/origin/gggg
       remotes/origin/main

Switching back to the correctly cased branch does not seem to put back
everything in order (list of branches is broken), but "git push"
works, at least:
    $ git checkout -
     Switched to branch 'gggg'
       Your branch is ahead of 'origin/gggg' by 1 commit.
       (use "git push" to publish your local commits)
    $ git branch -vv
     GGGG 2ed967b foobar
     main 51789b0 [origin/main] foo
    $ git push
     Enumerating objects: 4, done.
     Counting objects: 100% (4/4), done.
     Delta compression using up to 4 threads
     Compressing objects: 100% (2/2), done.
     Writing objects: 100% (3/3), 962 bytes | 962.00 KiB/s, done.
     Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
     To github.mycompany.com:ID123456/test_branches.git
     8f2fdd0..2ed967b  gggg -> gggg

Even trying to switch to other branches, still does not correct this situation:
    $ git branch -vv
      GGGG 2ed967b foobar
      main 51789b0 [origin/main] foo
    $ git checkout main
     Switched to branch 'main'
     Your branch is up to date with 'origin/main'.
    $ git branch -vv
       GGGG 2ed967b foobar
     * main 51789b0 [origin/main] foo
    $ git checkout gggg
     Switched to branch 'gggg'
     Your branch is up to date with 'origin/gggg'.
    $ git branch -vv
      GGGG 2ed967b foobar
      main 51789b0 [origin/main] foo
   $ git branch -a
      GGGG
      main
     remotes/origin/gggg
     remotes/origin/main
    $ git checkout Gggg
     Switched to branch 'Gggg'
    $ git branch -a
      GGGG
      main
      remotes/origin/gggg
      remotes/origin/main

 Any idea of what's going on? And how to fix it?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git oddities with case of branch names on Windows
  2023-02-15 13:28 ` Git oddities with case of branch names on Windows Patakreyp Chandler
@ 2023-02-15 16:53   ` Torsten Bögershausen
  2023-02-16  7:03     ` Patakreyp Chandler
  0 siblings, 1 reply; 3+ messages in thread
From: Torsten Bögershausen @ 2023-02-15 16:53 UTC (permalink / raw)
  To: Patakreyp Chandler; +Cc: git

On Wed, Feb 15, 2023 at 02:28:38PM +0100, Patakreyp Chandler wrote:
> Hello,
>
> Here is a scenario for some oddities (bugs?) for case of branch names
> (at least with git version 2.37.3.windows.1).
>
> First, we have created an empty git repository on our internal GitHub
> server and we clone this repository
>     $ git clone git@github.mycompany.com:ID123456/test_branches.git ppppppp
>     Cloning into 'ppppppp'...
>     warning: You appear to have cloned an empty repository.
>
> Then we create an object in this repository on main branch, we add,
> commit and push it:
>     $ cd ppppppp/
>     $ echo foo > foo
>     $ git add foo
>      warning: in the working copy of 'foo', LF will be replaced by
> CRLF the next time Git touches it
>     $ git commit -m 'foo'
>      [main (root-commit) 51789b0] foo
>      1 file changed, 1 insertion(+)
>      create mode 100644 foo
>     $ git push
>      Enumerating objects: 3, done.
>      Counting objects: 100% (3/3), done.
>      Writing objects: 100% (3/3), 869 bytes | 869.00 KiB/s, done.
>      Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
>      To github.mycompany.com:ID123456/test_branches.git
>      * [new branch]      main -> main
>
> We create a new branch in this repository and switch to it:
>     $ git checkout -b gggg
>      Switched to a new branch 'gggg'
>
> We create an object in this repository on the new branch, we add,
> commit and push it:
>     $ echo bar > bar
>     $ git add bar
>      warning: in the working copy of 'bar', LF will be replaced by
> CRLF the next time Git touches it
>     $ git commit -m 'bar'
>      [gggg 8f2fdd0] bar
>      1 file changed, 1 insertion(+)
>      create mode 100644 bar
>     $ git push --set-upstream origin gggg
>      Enumerating objects: 4, done.
>      Counting objects: 100% (4/4), done.
>      Delta compression using up to 4 threads
>      Compressing objects: 100% (2/2), done.
>      Writing objects: 100% (3/3), 929 bytes | 929.00 KiB/s, done.
>      Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
>      remote:
>      remote: Create a pull request for 'gggg' on GitHub by visiting:
>      remote:
> https://github.mycompany.com/ID123456/test_branches/pull/new/gggg
>      remote:
>      To github.mycompany.com:ID123456/test_branches.git
>      * [new branch]      gggg -> gggg
>      branch 'gggg' set up to track 'origin/gggg'.
>
> If we look at the local branches, everything is normal:
>     $ git branch -vv
>      * gggg 8f2fdd0 [origin/gggg] bar
>        main 51789b0 [origin/main] foo
>
> Now we “switch” to the exact same branch but with a typo (here, 'GGGG'
> instead of 'gggg') in the case of branch name (this does not work with
> git on Linux "error: pathspec 'GGGG' did not match any file(s) known
> to git."):
>     $ git checkout GGGG
>      Switched to branch 'GGGG'
>
> We create an object in this repository on the (not really) new branch
> (with faulty case name), we add, commit and (try to) push it:
>     $ echo foobar > foobar
>     $ git add foobar
>      warning: in the working copy of 'foobar', LF will be replaced by
> CRLF the next time Git touches it
>     $ git commit -m 'foobar'
>      [GGGG 2ed967b] foobar
>      1 file changed, 1 insertion(+)
>      create mode 100644 foobar
>     $ git push
>     fatal: The current branch GGGG has no upstream branch.
>     To push the current branch and set the remote as upstream, use
>             git push --set-upstream origin GGGG
>     To have this happen automatically for branches without a tracking
>     upstream, see 'push.autoSetupRemote' in 'git help config'.
>
> Pushing actually fails because git says "The current branch GGGG has
> no upstream branch ", and if we check this badly cased branch ("GGGG")
> has no upstream tracked branch, but is still the same correctly cased
> branch ("gggg"):
>     $ git branch -vv
>      * GGGG 2ed967b foobar
>         main 51789b0 [origin/main] foo
>     $ git branch -a
>      * GGGG
>        main
>        remotes/origin/gggg
>        remotes/origin/main
>
> Switching back to the correctly cased branch does not seem to put back
> everything in order (list of branches is broken), but "git push"
> works, at least:
>     $ git checkout -
>      Switched to branch 'gggg'
>        Your branch is ahead of 'origin/gggg' by 1 commit.
>        (use "git push" to publish your local commits)
>     $ git branch -vv
>      GGGG 2ed967b foobar
>      main 51789b0 [origin/main] foo
>     $ git push
>      Enumerating objects: 4, done.
>      Counting objects: 100% (4/4), done.
>      Delta compression using up to 4 threads
>      Compressing objects: 100% (2/2), done.
>      Writing objects: 100% (3/3), 962 bytes | 962.00 KiB/s, done.
>      Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
>      To github.mycompany.com:ID123456/test_branches.git
>      8f2fdd0..2ed967b  gggg -> gggg
>
> Even trying to switch to other branches, still does not correct this situation:
>     $ git branch -vv
>       GGGG 2ed967b foobar
>       main 51789b0 [origin/main] foo
>     $ git checkout main
>      Switched to branch 'main'
>      Your branch is up to date with 'origin/main'.
>     $ git branch -vv
>        GGGG 2ed967b foobar
>      * main 51789b0 [origin/main] foo
>     $ git checkout gggg
>      Switched to branch 'gggg'
>      Your branch is up to date with 'origin/gggg'.
>     $ git branch -vv
>       GGGG 2ed967b foobar
>       main 51789b0 [origin/main] foo
>    $ git branch -a
>       GGGG
>       main
>      remotes/origin/gggg
>      remotes/origin/main
>     $ git checkout Gggg
>      Switched to branch 'Gggg'
>     $ git branch -a
>       GGGG
>       main
>       remotes/origin/gggg
>       remotes/origin/main
>
>  Any idea of what's going on? And how to fix it?

Thanks for the extensive written report,
very much appreciated to see a reproducable example.
For a longer discussion, see below.

If you want to get rid of the GGGG branch, I would suggest something
in tis style:

git checkout -b tmpbranch
git branch -d GGGG
git checkout -b gggg
git branch -d tmpbranch

Is there a better solution ?
The problem is that your file system treats GGGG as gggg

Running `git pack-refs` could help. But there may be disadvantages
for people having many many branches.
(And then there had been some efforts to write a new backend for refs,
but I didn't follow that up).

My suggestion is to use lowercase for branch names only.

https://git.vger.kernel.narkive.com/PrwMfgXR/branch-name-case-sensitivity

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git oddities with case of branch names on Windows
  2023-02-15 16:53   ` Torsten Bögershausen
@ 2023-02-16  7:03     ` Patakreyp Chandler
  0 siblings, 0 replies; 3+ messages in thread
From: Patakreyp Chandler @ 2023-02-16  7:03 UTC (permalink / raw)
  To: git

Le mer. 15 févr. 2023 à 17:53, Torsten Bögershausen <tboegi@web.de> a écrit :
>
> On Wed, Feb 15, 2023 at 02:28:38PM +0100, Patakreyp Chandler wrote:
> > Hello,
> >
> > Here is a scenario for some oddities (bugs?) for case of branch names
> > (at least with git version 2.37.3.windows.1).
> >
> > First, we have created an empty git repository on our internal GitHub
> > server and we clone this repository
> >     $ git clone git@github.mycompany.com:ID123456/test_branches.git ppppppp
> >     Cloning into 'ppppppp'...
> >     warning: You appear to have cloned an empty repository.
> >
> > Then we create an object in this repository on main branch, we add,
> > commit and push it:
> >     $ cd ppppppp/
> >     $ echo foo > foo
> >     $ git add foo
> >      warning: in the working copy of 'foo', LF will be replaced by
> > CRLF the next time Git touches it
> >     $ git commit -m 'foo'
> >      [main (root-commit) 51789b0] foo
> >      1 file changed, 1 insertion(+)
> >      create mode 100644 foo
> >     $ git push
> >      Enumerating objects: 3, done.
> >      Counting objects: 100% (3/3), done.
> >      Writing objects: 100% (3/3), 869 bytes | 869.00 KiB/s, done.
> >      Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
> >      To github.mycompany.com:ID123456/test_branches.git
> >      * [new branch]      main -> main
> >
> > We create a new branch in this repository and switch to it:
> >     $ git checkout -b gggg
> >      Switched to a new branch 'gggg'
> >
> > We create an object in this repository on the new branch, we add,
> > commit and push it:
> >     $ echo bar > bar
> >     $ git add bar
> >      warning: in the working copy of 'bar', LF will be replaced by
> > CRLF the next time Git touches it
> >     $ git commit -m 'bar'
> >      [gggg 8f2fdd0] bar
> >      1 file changed, 1 insertion(+)
> >      create mode 100644 bar
> >     $ git push --set-upstream origin gggg
> >      Enumerating objects: 4, done.
> >      Counting objects: 100% (4/4), done.
> >      Delta compression using up to 4 threads
> >      Compressing objects: 100% (2/2), done.
> >      Writing objects: 100% (3/3), 929 bytes | 929.00 KiB/s, done.
> >      Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
> >      remote:
> >      remote: Create a pull request for 'gggg' on GitHub by visiting:
> >      remote:
> > https://github.mycompany.com/ID123456/test_branches/pull/new/gggg
> >      remote:
> >      To github.mycompany.com:ID123456/test_branches.git
> >      * [new branch]      gggg -> gggg
> >      branch 'gggg' set up to track 'origin/gggg'.
> >
> > If we look at the local branches, everything is normal:
> >     $ git branch -vv
> >      * gggg 8f2fdd0 [origin/gggg] bar
> >        main 51789b0 [origin/main] foo
> >
> > Now we “switch” to the exact same branch but with a typo (here, 'GGGG'
> > instead of 'gggg') in the case of branch name (this does not work with
> > git on Linux "error: pathspec 'GGGG' did not match any file(s) known
> > to git."):
> >     $ git checkout GGGG
> >      Switched to branch 'GGGG'
> >
> > We create an object in this repository on the (not really) new branch
> > (with faulty case name), we add, commit and (try to) push it:
> >     $ echo foobar > foobar
> >     $ git add foobar
> >      warning: in the working copy of 'foobar', LF will be replaced by
> > CRLF the next time Git touches it
> >     $ git commit -m 'foobar'
> >      [GGGG 2ed967b] foobar
> >      1 file changed, 1 insertion(+)
> >      create mode 100644 foobar
> >     $ git push
> >     fatal: The current branch GGGG has no upstream branch.
> >     To push the current branch and set the remote as upstream, use
> >             git push --set-upstream origin GGGG
> >     To have this happen automatically for branches without a tracking
> >     upstream, see 'push.autoSetupRemote' in 'git help config'.
> >
> > Pushing actually fails because git says "The current branch GGGG has
> > no upstream branch ", and if we check this badly cased branch ("GGGG")
> > has no upstream tracked branch, but is still the same correctly cased
> > branch ("gggg"):
> >     $ git branch -vv
> >      * GGGG 2ed967b foobar
> >         main 51789b0 [origin/main] foo
> >     $ git branch -a
> >      * GGGG
> >        main
> >        remotes/origin/gggg
> >        remotes/origin/main
> >
> > Switching back to the correctly cased branch does not seem to put back
> > everything in order (list of branches is broken), but "git push"
> > works, at least:
> >     $ git checkout -
> >      Switched to branch 'gggg'
> >        Your branch is ahead of 'origin/gggg' by 1 commit.
> >        (use "git push" to publish your local commits)
> >     $ git branch -vv
> >      GGGG 2ed967b foobar
> >      main 51789b0 [origin/main] foo
> >     $ git push
> >      Enumerating objects: 4, done.
> >      Counting objects: 100% (4/4), done.
> >      Delta compression using up to 4 threads
> >      Compressing objects: 100% (2/2), done.
> >      Writing objects: 100% (3/3), 962 bytes | 962.00 KiB/s, done.
> >      Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
> >      To github.mycompany.com:ID123456/test_branches.git
> >      8f2fdd0..2ed967b  gggg -> gggg
> >
> > Even trying to switch to other branches, still does not correct this situation:
> >     $ git branch -vv
> >       GGGG 2ed967b foobar
> >       main 51789b0 [origin/main] foo
> >     $ git checkout main
> >      Switched to branch 'main'
> >      Your branch is up to date with 'origin/main'.
> >     $ git branch -vv
> >        GGGG 2ed967b foobar
> >      * main 51789b0 [origin/main] foo
> >     $ git checkout gggg
> >      Switched to branch 'gggg'
> >      Your branch is up to date with 'origin/gggg'.
> >     $ git branch -vv
> >       GGGG 2ed967b foobar
> >       main 51789b0 [origin/main] foo
> >    $ git branch -a
> >       GGGG
> >       main
> >      remotes/origin/gggg
> >      remotes/origin/main
> >     $ git checkout Gggg
> >      Switched to branch 'Gggg'
> >     $ git branch -a
> >       GGGG
> >       main
> >       remotes/origin/gggg
> >       remotes/origin/main
> >
> >  Any idea of what's going on? And how to fix it?
>
> Thanks for the extensive written report,
> very much appreciated to see a reproducable example.
> For a longer discussion, see below.
>
> If you want to get rid of the GGGG branch, I would suggest something
> in tis style:
>
> git checkout -b tmpbranch
> git branch -d GGGG
> git checkout -b gggg
> git branch -d tmpbranch
>
> Is there a better solution ?
> The problem is that your file system treats GGGG as gggg
>
> Running `git pack-refs` could help. But there may be disadvantages
> for people having many many branches.
> (And then there had been some efforts to write a new backend for refs,
> but I didn't follow that up).
>
> My suggestion is to use lowercase for branch names only.
>
> https://git.vger.kernel.narkive.com/PrwMfgXR/branch-name-case-sensitivity

Thanks for the quick answer and I agree that branch names should be lowercase.

But my biggest concern is that, in my example, the 'GGGG' (or 'Gggg',
'gGgg' or whatever combination) branch does not really behaves as the
original 'gggg' branch.

'GGGG' has no tracked branch, instead of 'rorigin/gggg', causing 'git
push' to fail.

If branch 'gggg' could be written with every letters in any case, it
should behave identically whatever the cases, IMHO.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-16  7:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAAR1xzQwhbHNFFyTJQvkSVLJyJz_Gj5_FQ_udJrjM=ou+3GB3w@mail.gmail.com>
2023-02-15 13:28 ` Git oddities with case of branch names on Windows Patakreyp Chandler
2023-02-15 16:53   ` Torsten Bögershausen
2023-02-16  7:03     ` Patakreyp Chandler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.