2

I have a branch sf locally and a branch serverfix on remote.

The output of git remote show origin:

* remote origin
  Fetch URL: git@github.com:pr0g4amtest1ng/git-remote.git
  Push  URL: git@github.com:pr0g4amtest1ng/git-remote.git
  HEAD branch: master
  Remote branches:
    master    tracked
    serverfix tracked
  Local branches configured for 'git pull':
    master merges with remote master
    sf     merges with remote serverfix
  Local ref configured for 'git push':
    master pushes to master (up to date)

To make things easy for git push, I did the following:

git config push.default upstream
git push -u

Now if I run git remote show origin again

* remote origin
  Fetch URL: git@github.com:pr0g4amtest1ng/git-remote.git
  Push  URL: git@github.com:pr0g4amtest1ng/git-remote.git
  HEAD branch: master
  Remote branches:
    master    tracked
    serverfix tracked
  Local branches configured for 'git pull':
    master merges with remote master
    sf     merges with remote serverfix
  Local ref configured for 'git push':
    master pushes to master (up to date)

Strangely Local ref configured for 'git push': didn't change at all. Shouldn't it add an entry like sf pushes to serverfix (up to date) or something like that.

But if I do git push origin sf, it gives Everything up-to-date and it is not creating an sf branch on remote anymore, that means it is tracking.

How will I know which branch are being tracked for 'git push' ? Why there isn't an entry added for Local ref configured for 'git push': or when an entry will be added for that matter.

Abhisek
  • 2,680
  • 3
  • 14
  • 24

2 Answers2

2

You have two choices

  • First choice:

    git config remote.origin.push <local_branch_refs>:<remote_branch_refs>

  • Second choice: git config --edit to edit the .git/config file.

    [remote "origin"]
     push = <local_branch_refs>:<remote_branch_refs>


For your case, it should be:

git config remote.origin.push refs/heads/sf:/refs/heads/serverfix

After that, you can see the updates in Local ref configured for 'git push' section by git remote show origin.

JsonBruce
  • 991
  • 9
  • 11
0

push.default = upstream: push the current branch

To list branches with their upstreams: git branch -vv.

phd
  • 57,284
  • 10
  • 68
  • 103
  • then what about the section `Local ref configured for 'git push':` in `git remote show origin` and if `push.default upstream` is what you said then what about `push.default matching` ? – Abhisek Jun 11 '17 at 16:20
  • 1
    about `git branch -vv`, it is not showing the tracking information about `git push` rather for `git fetch` – Abhisek Jun 11 '17 at 16:47
  • matching - push all branches **having the same name on both ends**. By default `git fetch` is configured to fetch the same branches from the same remote as `git push`. – phd Jun 11 '17 at 16:56
  • well you mean the `upstream` and `matching` both will responsible for branches having same name ? – Abhisek Jun 11 '17 at 17:02
  • (I updated my answer.) With `push.default = upstream` you can push branches one by one. With `matching` you can push many but only to branches with the same names. To push many branches to remote branches with different names you should carefully configure branches in `.git/config`. See https://stackoverflow.com/q/7583091/7976758 and follow links from there. – phd Jun 11 '17 at 17:39
  • your updated answer is correct in their own context but that doesn't answer my question – Abhisek Jun 12 '17 at 08:13