Timeline for Move branch pointer to different commit without checkout
Current License: CC BY-SA 4.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 6, 2022 at 16:14 | history | edited | Nathan | CC BY-SA 4.0 |
Changed -f to --force. Added that new-tip-commit can be a branch name.
|
Sep 3, 2020 at 8:38 | comment | added | klapshin |
You may want to use git checkout <branch-name> after git branch -f <branch-name> otherwise you will end up with head still pointing at the <new-tip-commit> , that look confusing for me
|
|
Aug 13, 2020 at 5:13 | history | edited | Brian Burns | CC BY-SA 4.0 |
explain second param is optional
|
May 7, 2020 at 15:17 | comment | added | Keith Russell |
@starfry, the command for moving the head of your current branch is git reset . You'd do git reset --hard HEAD^ or git reset --keep HEAD^ , depending on the behavior you desire.
|
|
Apr 29, 2019 at 9:06 | history | edited | Good Night Nerd Pride | CC BY-SA 4.0 |
Signify place holders with `<` and `>`.
|
Oct 23, 2018 at 12:21 | comment | added | PeterG |
This seems to have a side-effect. If your new-tip-commit is a remote branch, it is also set as the upstream for your branch-name . Is there a way around this?
|
|
May 30, 2018 at 9:12 | comment | added | Abhijeet Nagre | What is 'new-tip-commit'? | |
May 16, 2017 at 9:11 | comment | added | starfry |
I wanted to move the head of my current branch back one commit: git checkout HEAD^ && git branch -f mybranch HEAD && git checkout mybranch worked for me.
|
|
Feb 24, 2016 at 18:26 | history | rollback | Chris Johnsen |
Rollback to Revision 1
|
|
Feb 24, 2016 at 8:10 | history | edited | knocte | CC BY-SA 3.0 |
added 114 characters in body
|
Apr 30, 2015 at 1:02 | comment | added | Vladimir Panteleev |
This won't work if the branch you're trying to move is your current branch (HEAD points to it).
|
|
Mar 11, 2014 at 9:58 | comment | added | Tim Kist | Very useful if you want to change where another branch is pointing without checking it out. | |
Dec 5, 2012 at 18:22 | comment | added | AlexChaffee |
This is a better answer since it handles the 99% case and actually conforms to the documentation. git help branch says " -f, --force Reset <branchname> to <startpoint> if <branchname> exists already. Without -f git branch refuses to change an existing branch."
|
|
Nov 25, 2011 at 12:45 | vote | accept | Mot | ||
Nov 25, 2011 at 12:45 | |||||
Oct 7, 2011 at 15:53 | review | Suggested edits | |||
Oct 7, 2011 at 17:23 | |||||
Mar 29, 2011 at 10:38 | history | answered | Chris Johnsen | CC BY-SA 2.5 |