
You cannot, in advance, guess which strategy your future team will use. My current team uses a one feature-one branch strategy, so the first step of starting to work on a feature/bug/ticket is to create a branch locally, then do your work there, and then once done (and green, and reviewed), merge the branch into master. That was behind the curtains, though, and was invisible. My previous team used an "live-at-head" strategy, so we would all commit to the main branch - of course, we used CI & Pull-Request so in practice the CI created a branch, ran the tests on that, and then when approved rebased the branch on master and fast-forwarded it. Even on private repositories, setup your CI, with linter and test-suite, and get used to have every PR scrutinized.īranching is orthogonal to a green main branch, and mostly a matter of team preference. This is what you should be getting used to. In a team setting, it also means that starting work on a new feature may be hampered by first having to figure out whether the latest commit is green or not. And thus bisecting to find which version introduced an issue may not be possible.Pulling an older version to compare its behavior with the newer one may mean hitting a "dud" and encountering unrelated issues.The alternative (not all commits are green) mean that:
#Commit and push to a different branch not master git full
That is, I can check it out, run the full test-suite, and it comes back green. Then, once you've completed the change, tested it, and verified that you're happy with the results, then you can merge it back into the main branch.Īny commit on the main branch should always be green. So my suggestion (when working by yourself) is: small and low-risk changes can go directly into the main branch, but if you're going to make a major and/or a risky change, create a side branch and make the change there first. In the worst-case scenario, you can just delete the messed-up side branch (or keep it but just never merge it back), and life can go on without requiring any cleanup of the main branch. The advantage of making changes in a separate branch is that if it all goes pear-shaped, you still have a perfectly functional main branch that you never damaged with your ill-fated changes. It also means that there is only one version of your program that needs testing, which increases the chances of you noticing and fixing any bugs that might creep in to your program (it's hard to notice a bug that's present only in a branch that you're not currently building from). The refs/remotes have references to your remote repository Git objects.The advantage of committing directly to the main branch is simplicity - if all of your changes are commited to the same branch, then you don't have to keep track of which changes were committed where, and you don't have to deal with (potentially messy) branch-merging later on. The refs/heads directory stores the references to objects in your local repository. These refspecs are stored in special directories inside your repository. In Git, we refer (pun intended) to these references as refspecs. This makes it easy to quickly access the various Git objects without always using cryptic SHA hashes. Git internally stores references to all the objects in your repository.

The git push command with its refspecs options saves the day for you in such cases.įinally, before we sign off, let’s dig deeper into refspecs. This is especially true when you work on multiple projects involving large teams. Sometimes, there is a mismatch between the naming schemes in the central (remote) repository and your local setup.

You would need to push it into each project with a different name. You could love even a simple generic feature like a Halloween-themed menu you designed and would want it in many of your apps.

Suppose you develop a cool feature or module, and you want to push it into more than one project that you work on. When Would We Like to Git Push to Another BranchĪ few use cases when we would want to git push a new branch are:
