0

After I pushed my work to the feature branch of a remote repository, someone merged it to the main branch.

Since then, I haven't made any change to my local working directory and local repository and the remote repository, while others have made changes to the remote repository.

Now I want to get the latest work from the remote repository,

  • is git pull the correct command?
  • will I not need to merge, because my last commit is an ancestor of the current commit on the main branch?

Running git pull doesn't succeed. The output of running git pull contains the following

There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> core-81

What does it mean?

Thanks.

Tim
  • 1
  • 141
  • 372
  • 590
  • 1
    `git pull` is basically a `git fetch` followed by `git merge`. you can alway fetch the latest changes and merge it manually – mic4ael Aug 09 '16 at 19:44
  • Thanks and see the output of `git pull` I just added. – Tim Aug 09 '16 at 19:47
  • If your current branch doesn't track any remote branch, pulling doesn't make any sense. You can still use `git fetch` to retrieve current versions of all upstream branches. As pointed out above, `git pull` is essentially `git fetch` followed by `git merge`, but the merge step only makes sense if there is an upstream branch to merge into the current branch. – Sven Marnach Aug 09 '16 at 19:55
  • How do I check if my current branch track any remote branch? Do you mean a merged local feature branch will not track the main branch in remote repo? – Tim Aug 09 '16 at 19:56
  • @Tim: You already did. Look at the output of `git pull`. – Sven Marnach Aug 09 '16 at 19:57
  • @Sven, `get fetch` quickly finished running, and doesn't seem to anything – Tim Aug 09 '16 at 20:14
  • If `git fetch` doesn't do anything, it's because there is nothing to fetch. I agree it could be more verbose in this case. – Sven Marnach Aug 10 '16 at 16:09

2 Answers2

1

You need to switch to the main branch by running

git checkout master

change master to your main branch (for example development). Then run git pull to get the latest work from the main branch.

The most general usage of git pull is

git pull origin branch

Where origin is the remote repository, and branch is the remote branch to pull information from. However, you can run

git push -u origin branch
# or
git branch -u origin/branch branch

This command (-u stands for --set-upstream) will set a remote branch as a tracking for this local branch and later on you will only need to run git pull for this branch

White Oak
  • 49
  • 5
  • 1
    (I put this same comment in on e.doroskevic's answer, but just in case, I will repeat it.) While `git pull` has a `-u` option, it simply passes it on to `git fetch`, where it means `--update-head-ok`. As [the documentation](https://www.kernel.org/pub/software/scm/git/docs/git-pull.html) says, "unless you are implementing your own Porcelain you are not supposed to use it." Note that this is quite different from `git push -u`, which you *are* supposed to use as needed. – torek Aug 09 '16 at 21:40
  • @torek, whoops! Thank you very much, I fixed that. – White Oak Aug 09 '16 at 22:08
1

Description

Besically, if you haven't set up upstream for your branch - it will fail to pull; simply because git has no idea where to pull from

In order to pull branch you are interested in you can run

git pull <remote> <branch>

Note: you can add -u here to set up upstream at this point

as git is suggesting to you in the output provided.

git branch --set-upstream-to <branch> <remote>/<branch>

This instruction will manually set up upstream for specified branch as in the above signature.

You can also set this up automatically when pushing by doing

git push -u <remote> <branch>

Note: -u sets up an upstream

EDIT 1

@torek

While git pull has a -u option, it simply passes it on to git fetch, where it means --update-head-ok. As the documentation says, "unless you are implementing your own Porcelain you are not supposed to use it." Note that this is quite different from git push -u, which you are supposed to use as needed.

Reference

6089294

Community
  • 1
  • 1
e.doroskevic
  • 2,129
  • 18
  • 25
  • 1
    While `git pull` has a `-u` option, it simply passes it on to `git fetch`, where it means `--update-head-ok`. As [the documentation](https://www.kernel.org/pub/software/scm/git/docs/git-pull.html) says, "unless you are implementing your own Porcelain you are not supposed to use it." Note that this is quite different from `git push -u`, which you *are* supposed to use as needed. – torek Aug 09 '16 at 21:37
  • @torek strikes again :), I will edit my post to include this information – e.doroskevic Aug 09 '16 at 22:38