Search code examples
gitrebase

Correct way to update checkout after a rebase?


Me and a colleague are both working on the same feature branch. We've both pulled the latest changes, and have no local changes, i.e we're both up to date, with all our changes pushed.

I've temporarily told them to not make any changes while I rebase the feature branch.

After doing the rebase and pushing it. What is the correct way for them to pick up the new changes?

git reset --hard hashOfCommit?


Solution

  • If you're working on the same branch with another contributor, you should always use git pull --rebase to pull in their work. If another contributor pushed commits to the branch after your last pull, and you have made commits on your local branch since then, git pull --rebase will pull the version of the branch from the remote and then rebase your local commits onto it.

    In the scenario where your partner force-pushed the branch, git pull --rebase will still work by skipping the already applied commits from your local branch.

    You can use the git config pull.rebase true configuration to make this the default behavior for git pull on your local repos.

    Note that git pull --rebase will still require you to resolve merge conflicts, if there are any. git reset --hard origin/branch-name is the fastest way to resolve the issue if you want to ignore all conflicts.