Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How git push current branch to another remote/origin?

Tags:

My .git/config:

[remote "origin"]     url = [email protected]:nfpyfzyf/test.git     fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"]     remote = origin     merge = refs/heads/master 

My local branches:

                     HEAD                      |                  F---G  feature**current branch                 /        C---D---E develop       /            A---B  master 

I'm now in feature branch, and want to push to remote. What is the current command, is itgit push origin feature? What will happen if I do git push?

like image 267
nfpyfzyf Avatar asked Apr 23 '13 10:04

nfpyfzyf


People also ask

How do I push a current branch to another remote?

In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.

How do I push a git repo to another remote?

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.

Does git push push to current branch?

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 .


1 Answers

To push a specific branch, run git push <remote> <branch>. In your case, your only defined remote is origin, and you want to push your feature branch, so that makes

$ git push origin feature

The “Examples” section of the git push documentation describes what happens if you run git push with no other arguments.

git push

Works like git push <remote>, where is the current branch’s remote (or origin, if no remote is configured for the current branch).

Given the configuration in your question, your feature branch does not have a remote configured, so the above invocation is equivalent to the next example.

git push origin

Without additional configuration, works like git push origin :

Following the daisy chain, we see that this is equivalent to

git push origin :

Push “matching” branches to origin. See in the OPTIONS section above for a description of "matching" branches.

The rules for matching branches are

The special refspec : (or +: to allow non-fast-forward updates) directs git to push “matching” branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file—see below) and no push.default configuration variable is set.

In your case, the only matching branch is master, so git push will push that branch and exit.

like image 70
Greg Bacon Avatar answered Sep 25 '22 08:09

Greg Bacon