git push to specific branch

后端 未结 4 1103
礼貌的吻别
礼貌的吻别 2021-01-29 22:39

Even after reading this question: git-push-current-branch, I am still having difficulty figuring out how I should write my git push command. As mentioned in the question link, i

相关标签:
4条回答
  • 2021-01-29 22:49

    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
    
    0 讨论(0)
  • 2021-01-29 23:05

    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.

    0 讨论(0)
  • 2021-01-29 23:06

    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.

    0 讨论(0)
  • 2021-01-29 23:08

    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:

    • where (URL-wise) that remote "lives" (e.g., ssh://hostname/path)
    • where pushes go, if different
    • what gets pushed, if you didn't say what branch(es) to push
    • what gets fetched when you run 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.

    0 讨论(0)
提交回复
热议问题