Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

I recently started using Git (previously I used subversion but I am now doing some collaborative work on a project that uses bitbucket and git).

All has been going well up until today when I find a well-meaning colleague who 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?

1 Answer

+1 vote
by (50.2k points)

If you have made some commits already then you could use:

git pull rebase

Warning: This will probably overwrite all your present files with the files as they are at the head of the branch in the remote repo.

If you didn't want it to you can undo these changes using:

git rebase -abort

The above pull command is more useful if you don't have any commits.

Browse Categories

...