In this lesson, you will learn how to share your local work with your team by pushing your feature branches to a remote repository on GitHub.
Why Push Your Branches?
So far, you’ve been working primarily on your local machine. While branching is great for organizing your own tasks, the true power of Git comes when you share that work with others. By pushing your branch to a remote repository (like GitHub), you create a "backup" of your progress and provide a space for your teammates to review your code or even contribute to the same feature.
Pushing Your Branch
When you create a new branch locally, it exists only on your computer. To make it visible to others, you need to "publish" it to the remote server.
Suppose you are working on a branch called feature-login. You can push it to the remote repository (usually named origin) with this command:
git push -u origin feature-login
Understanding the Command
origin: This is the default shorthand name for your remote repository.feature-login: This tells Git which specific local branch you want to send.-u: This stands for "upstream." By including this flag, you are telling Git to link your localfeature-loginbranch to the remote version.
Because you used the -u flag, you have established a "tracking" relationship. In the future, when you are on that branch and want to push new commits, you won't need to specify the remote name again; you can simply type git push.
Seeing the Results
Once you run this command, your branch will appear on your GitHub repository page. Now, when your teammates run git fetch or git pull, they will be able to see your branch in their list of remote branches, allowing them to switch to it and collaborate on your code.
Key Takeaway: Pushing your local branch with the -u flag not only publishes your work to the team but also links your local branch to the remote one for easier collaboration moving forward.