HEAD points to the top of the current branch. git can obtain the branch name from that. So it's the same as:
git push origin CURRENT_BRANCH_NAME
but you don't have to remember/type the current branch name. Also it prevents you from pushing to the wrong remote branch by accident.
If you want to push a different branch than the current one the command will not work.
Answer from hek2mgl on Stack OverflowHEAD points to the top of the current branch. git can obtain the branch name from that. So it's the same as:
git push origin CURRENT_BRANCH_NAME
but you don't have to remember/type the current branch name. Also it prevents you from pushing to the wrong remote branch by accident.
If you want to push a different branch than the current one the command will not work.
If you want to push into the specific remote branch you can run:
git push origin HEAD:<name-of-remote-branch>
This is what I encounter when I was trying to push my repo back to the remote branch.
Git push -u origin branch-name
git push origin head? - Stack Overflow
Difference between git push origin development and git push origin HEAD:development - Stack Overflow
What is “git push origin master?”
Videos
I am new to GitHub and from what I have understood that the command above will push the commits of the specified branch to github, and then I can just use git push. Should I do this for all branches? How does it know which branch I am referring to locally ( I believe the branch name that is written in the command is referring for the one on GitHub so how does it know which branch I am referring locally )? And will it push all branches that I used above command on them when I just type git push?
git push remote-name some-name
attempts to push any local branch named some-name to a remote branch also named some-name resolved at remote-name/some-name. Under the hood, it's looking for branch names under refs at each location (local, remote) that match.
Since your local copy of development hasn't been modified, you get a message that it's up to date, nothing to push.
The alternate version
git push remote-name HEAD:development
skips the part about looking for matching branch names in local and remote refs because you've given it an explicit branch via HEAD.
It still does use remote refs to determine the remote branch development. But then it uses HEAD of the current branch (your new test branch) for the commits to be pushed.
If you want to simply do git push from test branch and correctly push from test to remote/development, you can configure the default behavior of push to the "upstream" setting (note that the term "tracking" is an older term for "upstream" which is preferred).
Do
git config --global push.default upstream
to ensure that a plain git push will only attempt to push from the current branch to its registered upstream branch.
Without the setting, prior to git version 2.0, the default mode for a plain git push results in attempting to push all local branches to upstream branches with matching names at their configured remotes. For git 2.0 and newer, the default setting is simple which acts like upstream except that it also fails to push if the current branch doesn't share the same name as its configured remote.
The "upstream" setting is a good one because (a) it allows easily pushing branches regardless of whether their names match to their upstream names; (b) for versions prior to 2.0, it restricts a bare invocation of git push to affecting only the current branch, so if you're actively developing on multiple branches, git push will no longer unintentionally push other work unrelated to current branch work; (c) you will not need the form of git push that specifically names the remote and branch unless you're attempting to push to some branch that is not the configured upstream for your current branch -- and I'd argue this makes the most sense: you should only need to verbosely spell out the branches if you're not pushing from a local branch to its natural, configured upstream target. Even the 2.0 simple setting doesn't satisfy this.
remote-name is often origin, but can be any configured remote, added via various git commands or directly as in a .gitconfig file.
git push origin development pushes development branch
git push origin HEAD:development pushes current branch to remote's development
Most likely you are not in local development branch. Consider checking this with
git status
command.