Introduction
This article covers the following tech skills:
In a collaborative project, it is common to have multiple developers working on different branches of the same repository. When a developer pushes their changes to a branch that does not exist on the remote repository, the push will fail. This is where upstream branch creation comes in handy. By enabling automatic upstream branch creation on push, developers can avoid the hassle of manually creating the branch on the remote repository.
Automate Upstream Branch Creation
As a developer, you want to automate the process of creating upstream branches on push to avoid the hassle of manually creating the branch on the remote repository.
For this lab, you will fork the https://github.com/labex-labs/git-playground
repository to your account, using the git-playground
repository on your account to automatically create the upstream branch on push.
- On the GitHub website, log in to your account and find
https://github.com/labex-labs/git-playground
to fork the repository to your account. - On the page for your own forked repository, click the
Code
button and copy the URL of the repository. - Clone the repository, navigate to the directory and configure the identity:
git clone https://github.com/your-username/git-playground.git
cd git-playground
git config --global user.name "your-username"
git config --global user.email "your-email"
- Use the following command to enable automatic upstream branch creation on push:
git config --global push.default current
- Push a new branch called
new-feature
, which does not exist in the remote repository:
git checkout -b new-feature
git push
- Verify that the new branch has been created on the remote repository:
git ls-remote --heads origin
This is the result after completing the lab:
Summary
By enabling automatic upstream branch creation on push, developers can avoid the hassle of manually creating the branch on the remote repository. This lab has demonstrated how to enable this feature using the git config
command and how to push changes to a new branch that does not exist on the remote repository.
π Practice Now: Automate Upstream Branch Creation
Want to Learn More?
- π³ Learn the latest Git Skill Trees
- π Read More Git Tutorials
- π¬ Join our Discord or tweet us @WeAreLabEx
Top comments (0)