Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andyandy's avatar

git: Synchronize changes from Github

Locally I made changes in the project. Locally I commited them. When trying to push them to Github I found out somebody else commited changes to the repo before me. So git push will result in remote contains work that you do not have locally.

How do I pull changes and integrate them into my local repo (without losing my commit)? So I can push my commit?

0 likes
7 replies
tisuchi's avatar

@andyandy have you tried this?

git pull

It will pull all of your remote changes locally.

Then push your code-

git push
andyandy's avatar

@tisuchi If I git pull won't it overwrite my local commit?

I have a lot of work in that commit.

tisuchi's avatar

@andyandy If you have local changes, that you want to push, then

git add .
git commit -m "Write your commit message here"

It will add all of your local changes.

Then run-

git pull

With this, it will include your local change first, then pull the remote changes locally.

Now push your local code to remote:

git push

Side note: If you change a file that has been changed remotely also, that time you may get the conflict.

I suggest you understand git more. It's really fun.

1 like
andyandy's avatar

@tisuchi

Well, it doesn't like git pull.

fatal: Not possible to fast-forward, aborting.

martinbean's avatar
Level 80

@andyandy If it’s all in the same branch then you need to rebase your changes on top of what’s been committed, and resolve any conflicts between yours and the other person’s work.

This is why it’s a good idea to use branches and propose changes to a “main” branch using pull requests.

andyandy's avatar

@martinbean

Yes, same branch. Branch dev-my-branch and other guy unexpectedly pushed there some changes.

I will look how to rebase.

andyandy's avatar

@martinbean

So if I understand it correctly, while in the branch I will git pull --rebase which will download remote changes and put my local commit on top of that? And then I will be able to git push my changes.

Please or to participate in this conversation.