git reset --hard origin/branch_to_overwrite
from : https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files
git reset --hard origin/branch_to_overwrite
from : https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files
git push origin local_branch:remote_branch
EX: git push origin p-other/LUWA-15566-Feature1:p-api/Feature2
You can just run the command
git parent
to find the parent of the branch, if you add the @Joe Chrysler's answer as a git alias. It will simplify the usage.
Open gitconfig file located at "~/.gitconfig" by using any text editor. ( For linux). And for Windows the ".gitconfig" path is generally located at c:\users\your-user\.gitconfig
vim ~/.gitconfig
Add the following alias command in the file:
[alias]
parent = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"
Save and exit the editor.
Run the command git parent
That's it!
from : https://stackoverflow.com/questions/3161204/how-to-find-the-nearest-parent-of-a-git-branch
FINALLY VERSION:
git show-branch -a \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| head -n1 \
| sed 's/.*\[\(.*\)\].*/\1/' \
| sed 's/[\^~].*//'
parent = "!git show-branch -a | grep '\\*' | grep -v `git rev-parse --abbrev-ref HEAD` | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'"
from : https://archive.hankchizljaw.com/notes/24/
You can use the reflog to find the first action before the rebase started and then reset --hard back to it. e.g.
$ git reflog
b710729 HEAD@{0}: rebase: some commit
5ad7c1c HEAD@{1}: rebase: another commit
deafcbf HEAD@{2}: checkout: moving from master to my-branch
...
$ git reset HEAD@{2} --hardfrom : https://stackoverflow.com/questions/41049711/git-how-to-rollback-a-rebase/41049867
There are a few ways to accomplish that:
# Rename the local branch to the new name
git branch -m <old_name> <new_name>
# Delete the old branch on remote - where <remote> is, for example, origin
git push <remote> --delete <old_name>
# Or shorter way to delete remote branch [:]
git push <remote> :<old_name>
# Push the new branch to remote
git push <remote> <new_name>
# Reset the upstream branch for the new_name local branch
git push <remote> -u <new_name>
Credit: ptim
# In this option, we will push the branch to the remote with the new name
# While keeping the local name as is
git push <remote> <remote>/<old_name>:refs/heads/<new_name> :<old_name>
When you use the git branch -m (move), Git is also updating your tracking branch with the new name.
git remote rename legacy legacy
git remote rename is trying to update your remote section in your configuration file. It will rename the remote with the given name to the new name, but in your case, it did not find any, so the renaming failed.
But it will not do what you think; it will rename your local configuration remote name and not the remote branch.
from : https://stackoverflow.com/questions/30590083/how-do-i-rename-both-a-git-local-and-remote-branch-name
ORIG_HEAD so this is usually as simple as:git reset --hard ORIG_HEAD
reset, rebase and merge all save your original HEAD pointer into ORIG_HEAD so, if you've done any of those commands since the rebase you're trying to undo then you'll have to use the reflog.