0

I am new to using GIT and I read the documentation guide but I can't seem to wrap my head around one thing.

Let's say the github source contains two branches, master and foobar. Now, when I do git branch on my system, it shows the names of both the branches which means I have both the branches on my system.

However, when I do a git checkout foobar and then do git pull, nothing really happens and instead git tells me,

`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> foobar 

`

It's only when I execute git pull origin foobar are the files modified and changed according to what has been updated on GitHub. Why does this happen? Where am I going wrong in doing git pull. AFAIK, I thought doing git pull will update my current branch to the latest code commits.

2 Answers 2

2

It sounds like you've created a local branch, foobar and, separately, a branch in your repository also called foobar. Despite having the same name, these branches have not been linked.

If you don't have a local branch foobar, then git checkout foobar becomes git checkout -b foobar --track origin/foobar

That second part (--track origin/foobar) is the part you want to pay attention to. That sets up your remote tracking for the initial checkout operation.

To fix the problem, you can execute the command you're being told to run--that'll just set the upstream branch for you after the fact. Note that in most cases, that's a bad idea (because of what the original checkout command should be doing). However, in your case it appears that you've created two separate but (essentially) identical branches.

Sign up to request clarification or add additional context in comments.

Comments

0

Git is a powerful tool, and most of it's power it gives to the user. Pulling = fetch + merging. Should git assume automatically that since you're on foobar locally (you checked out the local branch foobar, not remote) and if there is a remote it should pull from it? Git does not answer that question automatically.

From my experience with git, you will find it frustrating unless you start with a GUI for it, like sourcetree.

To summerise, to pull from remote you need to specify the remote branch, not local, and it will try to merge it with your current local working branch.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.