

This works by looking for a remote called upstream (or falling back to origin if it isn't found). Method 1 (hard reset local branch) Save your current work (optional step) By resetting your local Git branch to remote, you lose all the changes you made locally after the last commit of the remote repository. Hopefully this quick note might help someone who found themselves in the same position as me. The idea here is that we by issuing a single short command can fetch the latest master branch from the upstream repository of the codebase we're working on and set our local master branch to point to the most recent upstream/master one. It seems to be safe and to sort out the issue of ‘Your branch is ahead of ‘origin/master’ by x commits’.
GIT RESET BRANCH TO ORIGIN UPDATE
This will fetch and merge the current branch from the remote to my local branch- and also update my local tracking branch – origin/mybranch – to point to the latest commit – and – it will pull the remote master branch into origin/master and merge that into your local master branch.

After running a Git reset, it’s a good idea to run a Git status, as we do in the example below.
Here,The origin/main branch is the central repositorys version of your local.
This tree is in sync with the local filesystem and is representative of the immediate changes made to content in files and directories. To perform a Git reset with the soft option, use the command: git reset soft
The thing is – I was being too clever and trying to avoid pulling and updating master. The working directory The first tree we will examine is 'The Working Directory'. It says everything is up-to-date – but you get the horrible ‘Your branch is ahead of ‘origin/master’ by x commits’ message – WTF!ĮDIT: What this is saying is that your local master branch is ahead of your local copy of the remote master branch – origin/master – which you’ve just pulled down.ĮDIT: Your local master branch must have new commits which you had not pushed to origin. Which updates your local mybranch nicely.
GIT RESET BRANCH TO ORIGIN CODE
You have a remote repository and push some code updates to it from a local repository – you then switch to a different local repository and pull down the updated code from the remote repository with: Before you do this (if this your first time), make sure that you back up your branch before you reset it in case something goes wrong. This is an annoyingly simple issue – so simple that it may not be blogged elsewhere. Now that you have background knowledge of how remotes and branches work, let's solve our problem and reset a remote branch to origin using the git reset -hard command.
