A well meaning colleague has pushed changes to the Master instead of making a branch. This means that when I try to commit I get the error:
Updates were rejected because the tip of your current branch is behind
I know this should be resolved by making a pull request to re-sync things but I don't want to lose the changes I have made locally and I equally don't want to force the commit and wipe out the changes made by someone else.
What is the correct approach to allow me to merge the changes without losing either?
You are not currently on a branch. To push the history leading to the current (detached HEAD) state now, use
git push origin HEAD:<name-of-remote-branch>
I would do it this this way:
Stage all unstaged changes.
git add .
Stash the changes.
git stash save
Sync with remote.
git pull -r
Reapply the local changes.
git stash pop
or
git stash apply
I had this issue and I realized that .gitignore file is changed. So, I changed .gitignore and I could pull the changes.
This issue occurs when someone has commited the code to develop/master and latest code has not been rebased from develop/master and you're trying to overwrite new changes to develop/master branch
Solution:
This worked for me:
git branch
Copy the current branch name to clipboard
git pull origin <paste-branch-name>
git push
I was able to overcome this issue with the following Visual Studio 2017 change:
I had the exact same issue on my branch(lets call it branch B) and I followed three simple steps to get make it work
Now you can delete branch B and then rename branch C to branch B.
Hope this helps.
I had the same problem. Unfortunately I was in wrong catalog level.
I tried to: git push -u origin master
-> there was a error
Then I tried: git pull --rebase
-> there still was a problem
Finally i change directory cd your_directory
Then I tried again ( git push
) and it works!
Source: Stackoverflow.com