Branching makes efficient ways to manage versioning of your application code. The popular version management tools supported branches like Git, SVN etc. Development in branching make process easier by splitting code in branches per modules.
Most of the Git providers (like: github.com, gitlab.com etc) provides option to create branch directly with web interface. But, in case you don’t have web interface access, You can also do the same by creating a branch in local repository and push changes to remote.
This article will help you to create a branch on local repository and then push branch to the remote Git repository.
1. Local Branch You Want to Publish
Switch to the local repository branch you want to publish to remote. To do this, use the following command:
git checkout feature-branch
Replace feature-login with a descriptive name for your new branch. This command creates a new branch and switches to it immediately.
In case, the local branch doesn’t yet exist, you can easily create it:
git checkout -b feature-login
2. Push the Local Branch to the Remote Repository
In order to share your local branch with others or to work on it from another computer, you need to push it to a remote repository. To do this, first, make sure you have a remote repository set up. If you’re using GitHub, GitLab, or Bitbucket, create a new repository on their platform.
Now, you’re ready to push your local branch to the remote repository. Use the following command:
git push -u origin feature-branch
This command pushes your local branch (“feature-login”) to the remote repository and sets up a tracking relationship between the local and remote branches.
You can also push the branch with another name to remote.
git push -u origin feature-branch:new-branch-name
Conclusion
Creating local and remote Git branches is an essential skill for developers working with version control. It allows you to work on multiple features or fixes simultaneously, without affecting the main branch. By following the steps outlined in this article, you’ll be well-equipped to manage your codebase effectively using Git branches.