简体   繁体   中英

After Pull Request, “Your branch is ahead of 'origin/master' by N commits”

Target

I want my local master to be matched with origin/master , as they have the same code.

Background

I'm not new to git , but I am new to Pull Requests and working into a team of developers.

We have 2 main branches: master and pre . We use Jira to create new branches, associated to features or incidents.

Our git flow is as follows:

  1. Open a branch from pre (using Jira)
  2. Code into branch
  3. Create a Pull Request to merge back to pre (reviewed)
  4. Again PR to merge to master (reviewed). We are in the process to implement some testing stage in pre , but right now is an empty step. So, once your new PR is approved goes from new-branch to pre , and without further reviews from pre to master .

What I did yesterday

So, I git checkout feature-branch in my local environment, made some modifications, git commit and git push origin feature-branch . The code was already on the remote repo, on Github.

I went to Github and created a PR (from Github website), assigning a reviewer. The reviewer approved it so I went to Github and clicked Merge button. Repeated this twice branch >> pre >> master , due to the mentioned reason.

Today, the issue

I want to work in another task. From my master branch in my local environment when I git pull origin master , I get this message:

From https://github.com/<user>/<reponame>
 * branch            master     -> FETCH_HEAD
Already up-to-date.

And git status outputs this:

# On branch master
# Your branch is ahead of 'origin/master' by 5 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

The first time I pulled, modifications were pulled from origin/master, but now this message gets appearing.

This repo has been used only by me these last days, so the code is exactly the same.

The questions

I didn't merge the code locally from feature-branch to pre to master . Should I?

What is happening here and how can I solve it?

PS: I read many answers but most of the Q/A are related to working on a local branch, not pushing the code to remote repo, which throws the same message.

Git fetch is what needed to be done here to update the refs.

From git fetch Documentation:

Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories. Remote-tracking branches are updated (see the description of below for ways to control this behavior).

Basically it means that git will collect all the meta-data about the commits from remote repo and save it on your local repo,without modifying any files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM