-1

I wonder if there is a possibility to just set a remote upstream for all branches and all future branches to a default value? Because I create feature branches and push them to origin. It's tiring to always do git push --set-upstream origin Feature-4578 for every new feature branch.

Can't I just do something like git remote add --track Feature-** origin git://path, so that all branches, current and future, with the pattern Feature-** are automatically set to remote origin?

devent
  • 11
  • 1
  • "It's tiring to always do `git push --set-upstream origin Feature-4578`" First of all, you can say that far more briefly. (Saying the name of the current branch is completely unnecessary, for example.) Second, why do you need to set an upstream at all? I push feature branches all day long and I never set an upstream. What specifically are you gaining by setting an upstream? – matt Apr 25 '22 at 12:54
  • @matt obviously I'm not the OP, but I do it so I can type `git push` without having to specify the remote branch to push to – evolutionxbox Apr 25 '22 at 12:55
  • @evolutionxbox I don't regard that as a convenience worth fighting for. First of all, if the PR is accepted straight off I'll never need to push again. Second, `git push origin @` is sufficiently easy to say (and I have a two letter alias for it). So why bother with an upstream? Upstream tracking is useful really only if you're going to be pulling (or fetch and merge) this branch — and for a feature branch that will probably never happen. – matt Apr 25 '22 at 13:12
  • @matt What does `@` represent here? I'm not familiar with that. – evolutionxbox Apr 25 '22 at 13:23
  • It's how you say "the name of the current branch". That's why I said that actually _saying_ the name of the current branch is unnecessary. – matt Apr 25 '22 at 13:25
  • @matt oooooo. I've been using a bash function for years. `@` is handy – evolutionxbox Apr 25 '22 at 13:25
  • if I checkout a new branch with `git checkout -b Feature` then try to push it `git push` it says `fatal: The current branch Bug_4580 has no upstream branch.` I thought it was the same for everybody. – devent Apr 28 '22 at 17:25

1 Answers1

1

It's tiring to always do git push --set-upstream origin Feature-4578 for every new feature branch

Then don't say it. Instead, say git push origin @.

Don't bother with setting the upstream (you don't need it), and don't bother with saying the branch's name (you say @ instead).

In fact, don't even bother saying that! I have an alias for it:

pp = push origin @

So I just say git pp. Is that easy enough?

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    Don't work here: `git push origin @ fatal: invalid refspec '@'` – devent Apr 28 '22 at 17:20
  • @devent Wow, that's really interesting! Are you using a really old version of Git? It would have to be earlier than 1.8.5 to get that error, I think. I truly recommend updating your Git; more recent versions have some _great_ improvements. Can you? – matt Apr 28 '22 at 17:42
  • Just to put this in perspective: I'm using 2.32.0, and the current version is 2.36.0. So you'd have to be waaaaaaay behind. – matt Apr 28 '22 at 17:43
  • Using git version 2.25.1 hm so it's really old. Never paid attention to the git version because all I do is commit and push. Linux is Linux Mint 20.2 – devent Apr 29 '22 at 06:47