How to Hard Push in Git From Branch A to B


To perform a hard push of branch b to branch a, you can use the following Git commands. This will forcefully push all changes from branch b to branch a, overwriting any differences


Switch to branch b -

git checkout b


Force push branch b to branch a -

git push -f origin b:a
  • git push -f: The -f flag forces the push, which will overwrite changes on the remote branch a with the contents of branch b.
  • origin b:a: This specifies that you want to push from branch b to branch a on the remote repository.

Be cautious with the -f (force) option, as it can overwrite history on branch a, potentially leading to loss of work for anyone else working on the project.