Simply push this branch to a different branch name

 git push -u origin localBranch:remoteBranch

If you don't want to set-upstream, just

 git push origin localBranch:remoteBranch
Answer from George Chen on Stack Overflow
Top answer
1 of 6
139

Simply push this branch to a different branch name

 git push -u origin localBranch:remoteBranch

If you don't want to set-upstream, just

 git push origin localBranch:remoteBranch
2 of 6
91

First, let's note that git push "wants" two more arguments and will make them up automatically if you don't supply them. The basic command is therefore git push remote refspec.

The remote part is usually trivial as it's almost always just the word origin. The trickier part is the refspec. Most commonly, people write a branch name here: git push origin master, for instance. This uses your local branch to push to a branch of the same name1 on the remote, creating it if necessary. But it doesn't have to be just a branch name.

In particular, a refspec has two colon-separated parts. For git push, the part on the left identifies what to push,2 and the part on the right identifies the name to give to the remote. The part on the left in this case would be branch_name and the part on the right would be branch_name_test. For instance:

git push origin foo:foo_test

As you are doing the push, you can tell your git push to set your branch's upstream name at the same time, by adding -u to the git push options. Setting the upstream name makes your git save the foo_test (or whatever) name, so that a future git push with no arguments, while you're on the foo branch, can try to push to foo_test on the remote (git also saves the remote, origin in this case, so that you don't have to enter that either).

You need only pass -u once: it basically just runs git branch --set-upstream-to for you. (If you pass -u again later, it re-runs the upstream-setting, changing it as directed; or you can run git branch --set-upstream-to yourself.)

However, if your git is 2.0 or newer, and you have not set any special configuration, you will run into the same kind of thing that had me enter footnote 1 above: push.default will be set to simple, which will refuse to push because the upstream's name differs from your own local name. If you set push.default to upstream, git will stop complaining—but the simplest solution is just to rename your local branch first, so that the local and remote names match. (What settings to set, and/or whether to rename your branch, are up to you.)


1More precisely, git consults your remote.remote.push setting to derive the upstream half of the refspec. If you haven't set anything here, the default is to use the same name.

2This doesn't have to be a branch name. For instance, you can supply HEAD, or a commit hash, here. If you use something other than a branch name, you may have to spell out the full refs/heads/branch on the right, though (it depends on what names are already on the remote).

🌐
GitHub
docs.github.com › en › get-started › using-git › pushing-commits-to-a-remote-repository
Pushing commits to a remote repository - GitHub Docs
When you clone a repository you own, you provide it with a remote URL that tells Git where to fetch and push updates. If you want to collaborate with the original repository, you'd add a new remote URL, typically called upstream, to your local Git clone: ... git fetch upstream # Grab the upstream remote's branches > remote: Counting objects: 75, done.
Discussions

How do I push a new local branch to a remote Git repository and track it too? - Stack Overflow
Push the local branch to the remote repository (i.e. publish), but make it trackable so that git pull and git push will work. ... lots of answers containing unrelated information (like how to create a branch) and if the answer applies, then information is missing regarding the magic parameters used. ... my workflow is: git checkout -b branch, git push => it prints an error message containing the command ... More on stackoverflow.com
🌐 stackoverflow.com
Is there a way to find out whether a branch on a local clone has been pushed or not?
Doing a fetch will bring the local cache of the remote's state up to date. From there, you can easily determine if a branch contains commits that are not in another branch, eg git log branch1..branch2 More on reddit.com
🌐 r/git
9
8
January 19, 2019
What is the proper way to sync changes made to upstream parent branch since I created my own feature branch?
Before making a PR do I need to get those changes down into my feature branch? The answer could be no or yes depending on what all got changed, so a good practice is always to assume that it will be yes. Here’s a good set of steps to take before making your pull request which are pretty similar to your workflow already git checkout master git pull git checkout FeatureA git rebase master Doing the git rebase master slaps your commits onto the commit history of master instead of creating the extra merge commit. You’ll have to fix the same conflicts as the merge but with the benefit of not having the extra merge commit looking all ugly in your history afterwards. Alternatively you could do a git checkout master git pull git checkout FeatureA git reset --soft master git commit At the cost of having to rewrite your commit messages. Remember, when doing a rebase or a reset you will need to git push -f (and add [origin branchname] afterwards for safety). A normal push will net you some errors. More on reddit.com
🌐 r/git
3
6
May 12, 2020
How to push to a remote without changing the upstream branch?
All that --set-upstream does is make changes to the local branch. If you don't want to do that, simply don't use it. Git doesn't care if the specified you're pushing to is upstream, downstream, or sideways of the local repository. More on reddit.com
🌐 r/git
13
5
July 11, 2019
🌐
Git
git-scm.com › docs › git-push
Git - git-push Documentation
Works like git push <remote>, where <remote> is the current branch’s remote (or origin, if no remote is configured for the current branch). ... Without additional configuration, pushes the current branch to the configured upstream (branch.<name>.merge configuration variable) if it has the ...
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › git-push-new-branch-remote-github-gitlab-upstream-example
Git push new local branch to remote
Follow these steps to have Git push a local branch to a remote repo: Create a new, local Git branch in your repository. Perform a git push origin -u <branchname> command to push to the remote repo.
🌐
Atlassian
atlassian.com › git › tutorials › syncing › git-push
Git Push | Atlassian Git Tutorial
The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch, but whereas fetching imports commits to local branches, pushing exports commits to remote ...
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to git push to remote branch
How to Git Push to Remote Branch
February 5, 2026 - The command pushes the new-feature branch to the custom repository. Note: Learn how to apply a single commit from one branch to another using Git cherry-pick. ... This tutorial showed several different options for pushing a local branch to a remote repository.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-push-a-local-branch-to-a-remote-repository-in-git
How to Push a Local Branch to a Remote Repository in Git? - GeeksforGeeks
July 23, 2025 - This command pushes the new-branch to the remote repository named origin. ... Always pull the latest changes from the remote repository before creating a new branch to avoid conflicts.
🌐
W3Schools
w3schools.com › git › git_branch_push_to_remote.asp
Git Push Branch to Remote
Git .gitignore Git .gitattributes Git Large File Storage (LFS) Git Signing Commits/Tags Git Cherrypick & Patch Git Merge Conflicts Git CI/CD Git Hooks Git Submodules Git Remote Advanced · Git Exercises Git Quiz Git Syllabus Git Study Plan Git Certificate · ❮ Previous Next ❯ · GitHub Bitbucket GitLab · This chapter explains how to push a branch from your local computer to {{title}}. Let's create a new local branch, make a change, and push it to {{title}}. git checkout -b update-readme Switched to a new branch 'update-readme' Edit a file, then check the status: git status ·
🌐
freeCodeCamp
freecodecamp.org › news › git-push-local-branch-to-remote-how-to-publish-a-new-branch-in-git
Git Push Local Branch to Remote – How to Publish a New Branch in Git
September 9, 2022 - To confirm the remote has been added, run git remote -v: To finally push the repo, run git push -u origin <branch-name> (“main” is the name of that branch for me). It could be master or Main for you.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-push-git-branch-to-remote
Push Git Branch to Remote - GeeksforGeeks
March 17, 2026 - Note: If no remote is configured, running git push will result in an error. ... This command pushes the local main branch to the remote repository.
🌐
GitKraken
gitkraken.com › home › learn › git push
Learn How to Git Push | Git Push Local Branch to Remote
March 14, 2022 - If you prefer not to set a default upstream, you can simply continue to use the push commands from the earlier examples. Either using one of the push options in the GUI like the Push button, or git push <remote name> <branch name> in the command ...
🌐
Git Tower
git-tower.com › learn › git › commands › git-push
git push - Publishing new local changes on a remote server | Learn Version Control with Git
In case you are using the Tower Git client, pushing to a remote is very easy: simply drag your current HEAD branch in the sidebar and drop it onto the desired remote branch - or click the "Push" button in the toolbar.
🌐
Graphite
graphite.com › guides › how-to-use-git-push-origin
How to use git push origin - Graphite
The git push origin command transfers commits from your local repository to a remote repository. This command updates the remote branch with commits from your current branch.
🌐
freeCodeCamp
freecodecamp.org › news › git-push-to-remote-branch-how-to-push-a-local-branch-to-origin
Git Push to Remote Branch – How to Push a Local Branch to Origin
April 26, 2021 - By default, Git chooses origin for the remote and your current branch as the branch to push. If your current branch is main, the command git push will supply the two default parameters—effectively running git push origin main.
🌐
Namehero
namehero.com › blog › how-to-use-git-to-push-to-a-different-remote-branch
How to Use Git to Push to a Different Remote Branch
October 24, 2024 - Instead, you can use the “–force-with-lease” option only to push those changes if the state of the remote branch matches what you have locally. The syntax will look something like this: ... The above command is a safe way to invoke the “force” parameter without messing up other people’s work. As you can see, using git to push your changes to a different remote branch is easy.
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Remote-Branches
Git - Remote Branches
Also, as long as you stay out of contact with your origin server, your origin/master pointer doesn’t move. Figure 31. Local and remote work can diverge · To synchronize your work with a given remote, you run a git fetch <remote> command (in our case, git fetch origin).
🌐
Warp
warp.dev › terminus › understanding-git-push-origin
Warp: Understanding Git Push Origin
January 31, 2024 - TIP: If you’re sure you’re on the branch you want to push, you can use symbolic references like HEAD to grab the <branchname> of the current branch without having to type it out. The git push origin HEAD command will push the current branch ...
🌐
GitHub
github.com › git-guides › git-push
Git Guides - git push · GitHub
This will also update any open pull requests with the branch that you're working on. As best practice, it's important to run the git pull command before you push any new changes to the remote branch.
🌐
Nick Janetakis
nickjanetakis.com › blog › use-git-push-origin-head-to-quickly-push-the-checked-out-branch
Use git push origin HEAD to Quickly Push the Checked Out Branch — Nick Janetakis
September 30, 2025 - It’s a little embarrassing because I only recently discovered you can run git push origin HEAD as a shortcut to push the current branch that you have checked out. This is great because it no longer means needing to remember individual branch ...