git making two commits when branch is behind

Hi,
I have made a local commit to the repo.
The remote branch is ahead by one commit. So I forgot to take the pull and commit my changes to local.
I did a git pull and git push
I saw the following 2 commits in the branch. The last one is weird.
whats the need for that to be created. how can i avoid that ?
So here my local branch was on 1f6a commit
and the origin was at 0ca commit

when i tried to push i got the error message :
On branch stage
Your branch and 'origin/stage' have diverged,
and have 1 and 2 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

after performing git pull i did git commit
and the top two commits were produced. Ideally only one commit should have
produced that of Remove nanosecond message.
How to avoid this top commit.
commit treeOne way is to uncommit your latest change and then take a git pull
How to uncommit the lates change that is in local ?

This problem is mainly coming when i am committing something and the origin branch is
ahead of local branch.
The Merge branch 'stage' of 10.1.5.12:app-portal into stage commit
which was automatically created has this in it. It shows two parents !!
parent
Thanks
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin McDanielSr. DeveloperCommented:
The messages I see make sense to me.
- The merge to get your local branch in sync wins because it was the last in.

The multiple parents also makes sense to me.
- As far as stage is concerned, there were two parent branches that led to the child branch you were merging into stage.
- At least, that's how it works in the environments I've used.

The only way I can immediately think of to avoid the situation is to squash the final commit so that it forces it to have only one parent. However, you'll lose the metadata and history from the parent that loses... so if that's important to your organization, you might simply want to leave yourself a sticky note on your monitor reminding you to always pull first and commit often.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Git

From novice to tech pro — start learning today.