In case, you have branch's conflict and don't want the commits caused by conflicts.
You are using the branch called "feat/api" and when switching, this error appears.
Switched to branch 'feat/api' Your branch and 'origin/feat/api' have diverged, and each has 2 and 5 submissions, respectively. (use "git pull" to merge the remote branch into yours)
You try to git pull origin and the following error appears again due to branch divergence
$ git pull hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation.
You try to git push the branch, but there is a conflict of 5 changes in front of this feat/api
$ git push origin feat/api To github.com:project/project.git ! [rejected] feat/api -> feat/api (non-fast-forward) error: failed to push some refs to 'github.com:project/project.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
An alternative to this is to change your current branch to remote. $git checkout origin/feat/api
make the changes, make the commits you have to make you have to do and when it's time to push the branch, just add the HEAD flag in front of branch.
$ git push origin HEAD:feat/api