This is part of a Git Tips series. For the complete set for beginners and intermediate Git users, see our white paper
Cuthbert made some commits, but instead of committing the relevant diagrams into the commit, he sent them to you by carrier pigeon. What a character.
You then copied them to where they’re supposed to be in the repository and committed them. But when he went to pull your commit down, Git refused, saying that untracked working files (his original diagrams) would be overwritten by the merge. He’s stuck, and spends his time gazing out the window instead of working.
In this example, you have committed the diagrams to the fun-times branch, and Cuthbert needs to store any local un-pushed commits so he doesn't lose them. Then replace his local diagrams with your committed ones.
This makes fun-times the current branch:
To maintain any recent commits he has made but not yet pushed, or keep some local files, Cuthbert needs to take further action first of all. Otherwise he will lose all of those local commits.
Option 1: This command replicates fun-times to a new branch, fun-times-local, without changing the current branch. So it is a branch of his local, un-pushed commits. This allows him to change or push them later on:
git branch fun-times-local
Option 2: This keeps any local files by stashing them, so they are not affected by the reset:
This brings him all the latest data from the remote repository, but makes no alterations to his files:
This replaces all his local files and index with those from the remote origin/fun-times branch:
git reset --hard origin/fun-times
Option 2 Resolution: This pops (re-instates) the stash of any local files that were stashed before in option 2: