ð§âðŧ New to Git or LabEx? We recommend starting with the Quick Start with Git course.
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.
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:
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.
We use cookies for a number of reasons, such as keeping the website reliable and secure, to improve your experience on our website and to see how you interact with it. By accepting, you agree to our use of such cookies. Privacy Policy