0

I created a new branch called MEWBRANCH and I did some changes there after "git add" and "git commit" (not push yet). So I checkout to master, merged the newbranch to master (git merge newbranch), so from the master I pushed (git push). Everything is ok on my master but now on my new branch I have the message "Your branch is ahead of 'origin/newbranch' by X commits". How can I fix that? or what I am doing wrong? Thanks

Binho
  • 23
  • 6
  • 1
    The message "Your branch is ahead of 'origin/newbranch' by X commits" is happening because you haven't pushed newbranch to origin/newbranch yet. Although I'm not sure what your aim is. Why not just work off master and delete newbranch? – dlever Apr 06 '21 at 19:37
  • I would like to keep the newbranch and not delete it, I just want to make it updated as a new one or make it sync with the remote one (without any ahead commits message) – Binho Apr 06 '21 at 19:40
  • In that case, just try doing a push with newbranch checked out? – dlever Apr 06 '21 at 19:43
  • Does this answer your question? [git: Your branch is ahead by X commits](https://stackoverflow.com/questions/2432579/git-your-branch-is-ahead-by-x-commits) – evolutionxbox Apr 06 '21 at 19:51
  • nope. Because is not my master branch the one ahead. – Binho Apr 06 '21 at 19:59
  • It will work if I merge new branch to master, in case I push from newbranch fist and after merge it ? – Binho Apr 06 '21 at 20:02
  • 1
    @Binho it shouldn’t matter. `master` is just a name. The concept is still the same – evolutionxbox Apr 06 '21 at 20:41

2 Answers2

1

Try this

git switch newbranch
git push origin

The message Your branch is ahead of 'origin/newbranch' by X commits simply informs you that you have commits locally that are not recorded in the remote repository. This is one of the blessings of Git since you can work on a project locally and wait to share your code until you've fully polished it off.

The above commands will send all local commits on your newbranch to your remote repository. If you add more commits later, then just repeat these same commands to share them too.

thehale
  • 913
  • 10
  • 18
0

... now on my new branch I have the message "Your branch is ahead of 'origin/newbranch' by X commits". How can I fix that? or what I am doing wrong?

Nothing is necessarily wrong here. There may be nothing to fix. This message is just informational. But you added this in a comment (note that a comment is the wrong place for this information; it needs to be in the original question):

I would like to keep the newbranch and not delete it, I just want to make it updated as a new one or make it sync with the remote one (without any ahead commits message).

In this case, you want to do what jhale1805 said. You can also refer to git: Your branch is ahead by X commits (as linked in this comment), but that's not quite a duplicate since that question and its existing answers are more about a branch name that's being updated by other people (not one that you are updating yourself). That question is also very old, being posted in 2010: it is mainly centered around an experience people used to get in Git versions predating Git 1.8.2, which was first released in March 2013.

torek
  • 448,244
  • 59
  • 642
  • 775