Don’t you just hate it when you’re getting that weird git error that prevents you from pulling to your local branch. For example:

fatal: Need to specify how to reconcile branches.

Well, you could delete your local folder and do a re-checkout. There are however other ways git can help you, even without falling back to the git reset --hard origin/master method.

Let’s just pretend to have the following scenario. You’re working in a team, and you’re all bound to use a git repo. As by good habit, your main branch is protected. Your team works with pull requests (or some call them merge requests), and you work on your branch. You do your work, test your stuff and are happy to check-in your code. It’s late, you want to go home and probably are a bit tired…​

So there you go to save and commit the work done…​

$ git add .
$ git commit -m "issue-589 solved that nasty bug that blah blah blah"
$ git push
! [rejected]
error: failed to push some refs...
$ git branch
* main

oh…​ stupid…​

$ git checkout -b issue-589-BugFixNameThatMakesSense
$ git add .
$ git commit -m "issue-589 solved that nasty bug that blah blah blah"
nothing to commit, working tree clean
$ git push --set-upstream origin issue-589-BugFixNameThatMakesSense

Yes, you were not paying attention…​ Your commit is part of your local main branch, but all seemed fine. But anyway, great news, the PR is approved the next day and merged to the main branch.

So there you go:

$ git checkout main
$ git pull
fatal: Need to specify how to reconcile branches.

What???

Did your local repo just get in a bad state? Well no, you’re lucky we can fix this..:

$ git pull --rebase
Successfully rebased and updated refs/heads/master.
$ git branch -d issue-589-BugFixNameThatMakesSense
deleting branch
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Done :)

shadow-left