Search code examples
gitgit-pushgit-config

Can I accidentally push more than one Git feature branch at the same time?


I've been using git for a few years now, so I'd say I'm "comfortable" with it but am by no means an expert.

Started a new job and my dev lead is trying to tell me that if I don't periodically delete/prune my local feature branches using git remote update origin --prune that git will auto-push them occassionally when pushing OTHER feature branches!!!

As an example of what he's saying here, let's say I've got a project called myproject which has the following branches:

  • master
  • develop
  • feature/one
  • feature/two
  • feature/three

Let's say feature/one and feature/two are old and have already been pushed to GitHub, merged to develop, and deleted from GitHub (the origin). feature/three is what I'm currently working on.

He's saying that if I don't git remote update origin --prune periodically, that I run the risk of re-pushing feature/one and feature/two to GitHub when I go to finally push my feature/three branch via git push!

This statement, if true, would not only shock me, it would leave me thunderstruck! Is it true, false, or partially correct, and why?!


Solution

  • Since Git 2.0 the default push.default config is set to simple. Only the current branch is pushed if it is connected with a remote tracking branch and the names are matching: https://git-scm.com/docs/git-config.

    Before, in Git 1.x., the default was matching. With this configuration all local branches with a equal named remote tracking branch were pushed together. If you had stale remote tracking branches, it could happen, that a git push re-created a removed remote branch.

    Maybe your dev lead is still on Git 1.x. or your team decided to use the old matching behavior as default.