Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I am getting the following when running git status

Your branch is ahead of 'origin/master' by 3 commits.

I have read on some other post the way to fix this is run git pull --rebase but what exactly is rebase, will I lose data or is this simple way to sync with master?

2 Answers

0 votes
by (27.5k points)

You get that message as a result of you made changes in your local master and you did not push them to remote.

You have many ways to "solve" it and it usually depends on how your workflow appearance is:

  • In a sensible workflow your remote copy of master ought to be the good one while your local copy of master is just a replica of the one in remote. nUsing this workflow you'll never get this message again.
  • If you work in another way and your local changes should be pushed then just git push origin assuming origin is your remote
  • If your local changes are bad then simply remove them or reset your local master to the state on remote git reset --hard origin/master
0 votes
ago by (3.1k points)

The message "Your branch is ahead of 'origin/master' by 3 commits" means there are three commits in your local branch that have not been pushed to the remote repository, origin/master. 
To push the commits to the remote repository, you would use: 
git push origin master 
This will update origin/master with your new commits; thereby both branches are synched. If you wish to avoid pushing those commits, or want to just simply remove them, then it's possible to use the reset or rebase method, but do that at your own risk because the last one will rewrite your commit history. 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...