Use the git push Command to Push Branch to Specific Remote Branch in Git. With the command git push , we also have to mention the specific remote branch name and the local branch name that we want to push our work.
Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch. Simply use a git push origin command on subsequent pushes of the new branch to the remote repo.
To push a local branch to the remote, right click on that branch in Team Explorer. From the context menu, that pops up on the screen, select Push Branch.
To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.
If your Local branch and remote branch is the same name then you can just do it:
git push origin branchName
When your local and remote branch name is different then you can just do it:
git push origin localBranchName:remoteBranchName
git push origin amd_qlp_tester
will work for you. If you just type git push
, then the remote of the current branch is the default value.
Syntax of push looks like this - git push <remote> <branch>
. If you look at your remote in .git/config
file, you will see an entry [remote "origin"]
which specifies url of the repository. So, in the first part of command you will tell Git where to find repository for this project, and then you just specify a branch.
The answers in question you linked-to are all about configuring git so that you can enter very short git push
commands and have them do whatever you want. Which is great, if you know what you want and how to spell that in Git-Ese, but you're new to git! :-)
In your case, Petr Mensik's answer is the (well, "a") right one. Here's why:
The command git push remote
roots around in your .git/config
file to find the named "remote" (e.g., origin
). The config file lists:
ssh://hostname/path
)git fetch remote
When you first cloned the repo—whenever that was—git set up default values for some of these. The URL is whatever you cloned from and the rest, if set or unset, are all "reasonable" defaults ... or, hmm, are they?
The issue with these is that people have changed their minds, over time, as to what is "reasonable". So now (depending on your version of git and whether you've configured things in detail), git may print a lot of warnings about defaults changing in the future. Adding the name of the "branch to push"—amd_qlp_tester
—(1) shuts it up, and (2) pushes just that one branch.
If you want to push more conveniently, you could do that with:
git push origin
or even:
git push
but whether that does what you want, depends on whether you agree with "early git authors" that the original defaults are reasonable, or "later git authors" that the original defaults aren't reasonable. So, when you want to do all the configuration stuff (eventually), see the question (and answers) you linked-to.
As for the name origin/amd_qlp_tester
in the first place: that's actually a local entity (a name kept inside your repo), even though it's called a "remote branch". It's git's best guess at "where amd_qlp_tester
is over there". Git updates it when it can.
I would like to add an updated answer - now I have been using git for a while, I find that I am often using the following commands to do any pushing (using the original question as the example):
git push origin amd_qlp_tester
- push to the branch located in the remote called origin
on remote-branch called amd_qlp_tester
.git push -u origin amd_qlp_tester
- same as last one, but sets the upstream linking the local branch to the remote branch so that next time you can just use git push/pull
if not already linked (only need to do it once).git push
- Once you have set the upstream you can just use this shorter version.Note -u
option is the short version of --set-upstream
- they are the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With