Some software development teams - who use project management tools like JIRA - enforce conventions
like naming your branches after the ticket IDs (e.g. T-1234
). This practice helps create automated
workflows and debugging. However, you might want a more descriptive branch name in your local
development workflow (e.g. feat-user-auth
).
In this post, we will be discussing how you can use different names for the same branch in your local and remote repositories.
How?
When we run the command git push origin branchName
, under the hood, Git expands the command to
git push origin branchName:branchName
. This expanded command means that the local branch named
“branchName” should be pushed to remote branch named “branchName”.
So, using this as a hint, the way to use a different branch name in remote would be:
git push origin localBranchName:remoteBranchName
In the context of our example, the command would be:
git push origin feat-user-auth:T-1234
--set-upstream
flag to the command, so that you can directly run git push
next time when trying to push the changes in feat-user-auth
to its corresponding remote branch - T-1234
.
Final words
When working in teams, having conventions for branch names is a very common practice. That does not mean that you should be losing your freedom to have your own custom branch names. Since now, you are in the position to have your own custom branch name while also following the conventions followed by your development team.