Open In App

How to Push a Local Branch to a Remote Repository in Git?

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Git is a widely used version control system, trusted by over 90% of developers worldwide, to track changes in codebases and streamline collaboration across teams. Mastering Git not only improves code management but also enhances team productivity and project scalability.


git
git


Pushing Local Branch

Pushing a local branch to a remote repository involves creating a branch locally, making some changes, committing those changes, and then pushing the branch to the remote repository so that others can access it.

Note: If you want to learn about Git Basics then check out this article - What is Git?

Steps to Push a Local Branch to a Remote Repository

Step 1: Check the Current Branch

First, you need to check which branch you are currently on. You can do this using the following command:

git branch

This command will list all the branches in your local repository and highlight the current branch with an asterisk (*).

git-branch
git branch

Step 2: Create a New Branch

If you want to create a new branch, you can use the following command:

git checkout -b new-branch

This command creates a new branch named new-branch and switches to it.

new-branch
new branch


Step 3: Make Changes and Commit

Make the necessary changes to your code. After making the changes, you need to stage and commit them:

git add .
git commit -m "Your commit message"

These commands stage all the changes and commit them with a message.

git commit
git commit


Step 4: Push the Branch to the Remote Repository

To push the branch to the remote repository, use the following command:

git push origin new-branch

This command pushes the new-branch to the remote repository named origin.

git-push
git push

Best Practices and Tips

  • Always pull the latest changes from the remote repository before creating a new branch to avoid conflicts.
  • Use descriptive names for your branches to make it clear what feature or fix they represent.
  • Regularly push your changes to avoid losing work and to keep the remote repository up to date.

Note: if you want to learn about git commands then check out- Git cheatsheet


Article Tags :

Similar Reads