git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Using the --track option when creating a branch

From
SBSanti Béjar <santi@agolina.net>
Date
Oct 30, 2008, 12:41 UTC
Message-ID
<adf1fd3d0810300541l7fb8b64nf9587fec4e481c58@mail.gmail.com>
In-Reply-To
<18697.41702.241183.408377@lisa.zopyra.com>
On Thu, Oct 30, 2008 at 1:04 PM, Bill Lear <rael@zopyra.com> wrote:
Show 27 quoted lines
> On Wednesday, October 29, 2008 at 22:12:18 (-0700) Sam Vilain writes:
>>On Wed, 2008-10-29 at 09:23 -0600, Bill Lear wrote:
>>> We use git in a way that makes it desirable for us to only push/pull
>>> to the same remote branch.  So, if I'm in branch X, I want 'git push'
>>> to push to origin/X, and 'git pull' to fetch into origin/X and then
>>> merge into X from origin/X.
>>>
>>> In other words, we want git push/pull to behave in branches other than
>>> master the same way it does when in master.
>>>
>>> I have discovered the '--track' option when creating a local branch,
>>> and this appears to me to be the thing that gives us the desired
>>> behavior.
>>
>>As things currently stand this is not achievable behaviour.  The
>>behaviour of 'git push' is to push all matching refs.  If you are lucky
>>this is what you intended, but it also pushes any changes to *other*
>>branches that you have made.
>>
>>I have tabled a change proposal to make it work as you suggest in a
>>separate thread.
>
> Ok, now I'm confused.  The ONLY thing I want to prevent is the
> "crossing of streams" issue.  If I am on branch X and issue 'git
> push', I want X, and ONLY X, to be pushed to the remote repository's X
> branch --- I don't care if other branches are pushed to their
> respective remote branches, as long as they don't get merged to X.
No branches will get merged in a push.
>
> So, are you saying that Santi was incorrect, and that in fact
> the push will result in a merge of the branches?

Sorry, I was (partly) incorrect because I was only talking about pull. For push you can add a "push = HEAD" config to the remote and then the "git push" will only push the current branch (with the corresponding matching remote branch).

$ git config remote.origin.push HEAD

Strictly speaking when you push (with the default config or with the above trick) you push matching branches (it doesn't matter what is the branch.<remote>.merge). Currently there is no way to say "push to the corresponding tracking branch"

Still I think this will work as you want (as long as your local and remote branch have the same name):

$ git clone $url $ cd path $ git config remote.origin.push HEAD $ git checkout -b branch origin/branch $ work, commit,... $ git push

HTH, Santi

Previous: Sam Vilain
Message 23 of 23 in “Using the --track option when creating a branch”
  1. Bill LearOct 29, 2008
  2. Santi BéjarOct 29, 2008
  3. Bill LearOct 29, 2008
  4. Sam VilainOct 30, 2008
  5. Bill LearOct 30, 2008
  6. Bill LearOct 30, 2008
  7. Andreas EricssonOct 30, 2008
  8. Samuel TardieuOct 30, 2008
  9. Andreas EricssonOct 30, 2008
  10. Samuel TardieuOct 30, 2008
  11. Pierre HabouzitOct 30, 2008
  12. Samuel TardieuOct 30, 2008
  13. Sam VilainOct 30, 2008
  14. Andreas EricssonOct 30, 2008
  15. Samuel TardieuOct 30, 2008
  16. Andreas EricssonOct 30, 2008
  17. Bill LearOct 30, 2008
  18. Marc BranchaudOct 30, 2008
  19. Sam VilainOct 30, 2008
  20. Jakub NarebskiOct 30, 2008
  21. Jeff KingNov 2, 2008
  22. Sam VilainOct 30, 2008
  23. Santi BéjarOct 30, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.