1

I am very new to git. Trying to figure some stuff out, so pls be gentle :-)

I'm trying to understand why git seems to create a new branch after an upstream git push.

starting sitation:

git checkout

says

FETCH_HEAD                      HEAD                            master                             pep-complaincy

then i do

git push --set-upstream pep8compliancy 

and i get

FETCH_HEAD                      HEAD                            master                          pep8compliancy/pep-complaincy   pep-complaincy

They way I understand is that by doing the push command, I link my local "pep-complaincy" branch to a remote "pep8complaincy" branch.

I would expect the output of "git checkout" either to read "pep-complaincy" (not showing the remote branch) OR to read "pep8compliancy/pep-complaincy" (indicating that the local branch is now linked to a remote branch).

Can't figure out why git is now showing 2 branches. Any help explaining this would be greatly appreciated.

mike
  • 1,233
  • 1
  • 15
  • 36
user2071786
  • 121
  • 1
  • 10

2 Answers2

2

First, don't use git checkout. It is an old, obsolete and confusing command used to:

Second, if you want to see the branches (local and remote) and their relationship, use:

git branch -avv
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • In fairness, neither `switch` nor `restore` seems to have *replaced* `checkout` yet; they are still documented as experimental. (This is distinct from `checkout` being deprecated but remaining along side stable `switch` and `restore` commands.) – chepner Sep 06 '20 at 14:23
  • @chepner I agree. Those commands are here to stay though, as confirmed last week: https://public-inbox.org/git/xmqq4kor6g8z.fsf@gitster.c.googlers.com/ – VonC Sep 06 '20 at 14:40
  • Ah, I didn't mean to imply they could go away, only that their behavior wasn't yet set in stone. Definitely use `switch` and `restore` in interactive use, where you can adjust your behavior as necessary, but `checkout` would still seem to be preferred if you want stability in a tool that wraps `git`. – chepner Sep 06 '20 at 14:45
0
git push --set-upstream pep8compliancy 

This will create a relationship between your current local branch (which is master) and the upstream branch pep8compliancy, which should probably be called pep8compliance so as to not offend the grammar Nazis out there :-)

If you want a new branch with the same upstream name, that would have been something like:

git co master                            # Start with master as baseline.
git pull                                 # Ensure up to date.
git co -b pep8compliancy                 # New local branch at same point.
git push --set-upstream pep8compliancy   # Push to upstream, linking names.
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953