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
?
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.
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.
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 .
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 (ororigin
, 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) directsgit
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 nopush.default
configuration variable is set.
In your case, the only matching branch is master
, so git push
will push that branch and exit.
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