threads / discuss / 61706

How to set a default/fallback upstream for new branches?

Subject: How to set a default/fallback upstream for new branches?

## tl;dr

One message between Jun 30, 2024 and Jun 30, 2024.

replies: 0people: 1as markdown or json

Björn Steinbrink· Jun 30, 2024, 11:16 UTC · lore
Hi folks,

My current git workflow is to have a central repo with a master/main branch that receives pull requests and I create my feature branches with that branch, i.e. origin/HEAD, as their upstream. I push using `git push origin HEAD`, using `--force-with-lease` when necessary due to rebasing.

That way pull/push do exactly what I want. I can update my commit series against upstream development on the main branch and update/replace the feature branch on the central version with my updated version of it.

To have the upstream for new branches set up automatically, I have autoSetupMerge set to "inherit". This works most of the time to get the upstream of a new branch set up correctly. But sometimes I need to work on a feature branch that exists in the central repo, for which I have no local branch head yet, e.g. because I took over from someone else. In that case, "git checkout foo" will not find any upstream to inherit:

    $ git checkout foo
    warning: asked to inherit tracking from 'refs/remotes/origin/foo',
but no remote is set
    Switched to a new branch 'foo'

In that situation, I'd like it to fall back to a default value like `origin/HEAD`.

Is there a way to do that?

Cheers, Björn

← back to recent threads