Locally I can commit without any branch active, i.e. after checking out to a commit but not a branch. Is it possible to push this commit which is not in any branch to remote?
EDIT: I'm just wondering theoretically how would git handle pushing a "no-branch" or is pushing only possible with branches.
Create a new branch with git checkout -b <branch_name> , and push it with git push -u origin <branch_name> . Then, everyone can see your branch, and if you need to make changes to it, it's as straightforward as changing to the branch, committing, and pushing it up.
No, git push only pushes commits from current local branch to remote branch that you specified in command.
Normally when one does a push, they push everything at once. However, git does provide a way to push only one commit at a time. The caveat is that the single commit you want to push must be directly above the tip of the remote branch (the oldest of your local commits).
No, you must make a commit before you can push. What is being pushed is the commit (or commits).
When you do
git push <remote> <source>:<destination>
The <source>
can be a commit, yes.
The <destination>
, however, is a bit more tricky. Take it from the doc :
It’s possible to push any type of object to any namespace outside of refs/{tags,heads}/. In the case of tags and commits, these will be treated as if they were the commits inside refs/heads/ for the purposes of whether the update is allowed.
So basically, you mostly push only to remote branches, but yes you can push commits, as long as moving from their current ref to the one you're pushing is a fast-forward merge.
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