Is it correct that I can just follow the instructions in the link I posted in the beginning, i.e.
local: git branch newbranch
local: git reset --hard HEAD~1 # only one commit was done
Yes.
and then -- well, now what? Do I just have to push again?
Yes. Moreover, you must push two branch names, and one of them needs a "forced push".
Or do I need to push the new branch explicitly? (Sorry if that's very basic, I never used this before).
While it's basic, there are a bunch of historical issues here. Git used to behave differently by default, and that behavior was wrong for most users. Git had options to override the default, but the default was wrong. So the default behavior changed in Git version 2.0. To get there, Git added a whole heap of configuration items, so that you can set the default behavior, if you liked the old behavior, and now we have to talk about the "default default behavior": i.e., what Git does if you don't set your own default.
I'm going to assume you did not set a lot of fiddly Git configuration knobs, so you are getting the default default. (I think this is the case because of a detail you mentioned: using minGW GUI.)
Assuming your Git version is at least 2.0, you would typically do this in two steps. (Because Git is what it is, you can do it all in one, in any version of Git, but let's do it in two.)
You didn't mention the name of the old branch (master
?) so I've used oldbranch
below, but you'll need to use whatever the actual name is.
git push -u origin newbranch
git push -f origin oldbranch
You can actually do these in either order.
The first command, git push -u origin newbranch
, has your Git call up another Git at origin
and deliver to them the new branch name, and any new commit(s) that go with it if they need them. The -u
flag means: "I am pretty sure this is a new branch for you; please create or update your newbranch
, making your branch match mine, and then I'll make mine have yours as my upstream." (See other questions for more about "upstreams".) Since this branch really is new to them, they will obey your polite request, creating the new branch with the one commit specific to that branch.
(That one commit points back to all the old commits on the old branch, so those commits are now on both branches, in both your Git repository, and the one at your remote.)
The second push, with -f
or --force
, tells your Git to call up the other Git again, and tell it (rather than politely asking it) to move its oldbranch
back to where you moved yours back to.
We have to force this push because they will normally say "no" to the more polite request, because that loses the new commit. But you want to toss the commit from the old branch.
(If someone else is sharing your fork on the remote, this step is slightly dangerous, because you're telling their Git to toss all new commits, including any that the other sharers might have pushed.)