Essential Git for Scientists
  • Introduction
  • Basic Concepts
    • Version Control
    • Git
    • Repo
    • Commits
    • Branches
    • Remotes
    • GitHub
    • De-centralisation
    • Summary
  • Basic Operations
    • Install Git
    • Create a Repo
    • Make a Commit
    • Inspect a Previous Commit
    • Revert a Change
    • Make a Branch
    • Extend a Branch
    • Fast-forward merge
    • Resolve conflicts
  • Intermediate Concepts
    • Commits
    • Three Trees
    • Rebase
    • Fetch
    • Pull
    • Push
  • Advanced Concepts
    • Reset
    • Interactive rebase
    • Formatted patches
    • Blame
    • Stash
    • Log filter
  • Cookbook
    • Undo
    • Branches
    • Diff
    • Stash
    • Merge
    • Hooks
    • Squashing
    • Rebase
    • Interactive Rebase
    • LFS
    • Submodules
    • Remote
    • Force push
    • Identify merged branches
    • Formated patches
    • Apply patches
    • Interactive rebase
    • Squash commits
    • Pull rebase
    • Log
    • Blame
    • Biset
    • Reset
  • Exercise
    • Exercise 1
    • Exercise 2
Powered by GitBook
On this page
  • Rationale
  • Commands
  1. Cookbook

Force push

Rationale

  • Typically you will fetch the remote, merge your code, then push it back.

  • In some cases, the remote is destroyed (e.g. by a mistake) and a merge is not desirable.

  • In this case, you just want to discard any changes in the remote and let it mirror your local repo.

  • The commits of the collaborators will be gone, and they need to sync the local repo afterwards.

  • Use with caution.

Commands

  • git push -f or git push --force

Collaborators syncing local repo

  • When the collaborators fetch from the remote, their origin/master will be in sync with the remote. However, their local repo is ahead of the origin/master, with those deleted commits still there.

  • They need to do a hard reset to sync with the origin/master.

    • git reset --hard origin/master

PreviousRemoteNextIdentify merged branches

Last updated 1 year ago