user1232138
user1232138

Reputation: 5541

There is no tracking information for the current branch. Please specify which branch you want to merge with

So I created a branch using Jira and I checked out that branch on my local system. Now I'm trying to do a git pull on my local system but I'm getting this message

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> feature/branch-name                                                                                                                                        mark-violation

What do I need to do? I have seen this link, but it wasn't clear to me.

Upvotes: 2

Views: 22588

Answers (3)

ConstructionCat
ConstructionCat

Reputation: 55

Check if you created your own branch by running the following command:

git branch -r

If it's not there, try:

git push -u origin yourbranch

Did not work? You may need to setup your email and name:

git config --global user.name "Some Dude"
git config --global user.email "[email protected]"

Now run the following:

git config --global --list
git commit --amend --author="Some Dude <[email protected]>"

At this point Nano will open in your terminal. Press Ctrl + O (write out). Press Enter (confirm the file name). Press Ctrl + X (exit Nano).

Finally, run:

git push -f origin yourbranch
OUTPUT: * [new branch]      yourbranch -> yourbranch

Upvotes: 0

teknopaul
teknopaul

Reputation: 6780

It may also be a long standing a bug in GIT.

This happens when you create a local branch and push it to a remote, so the tracking works. You can pull and push to and from it many times without problems, but if someone else pushes to the branch from a different clone, and then you pull, git looses the tracking information that was once working on your local copy.

git branch --set-upstream-to=origin/feature/branch-name

fixes it, but there is no sane reason why someone else pushing to a remote should break your local copies tracking information.

Upvotes: 0

matt
matt

Reputation: 536027

There are two Gits in this story. Let's call them Jira's Git and your local Git.

  • When you created a branch on Jira's Git, you did just that: created a branch on Jira's Git.

  • When you said git checkout -b branch-name on your local Git, you created a branch on your local Git.

Those two branches have no relationship to one another at all. They may happen to have the same name, but that's just a coincidence; they know nothing of one another.

You have not even told us if there is any relationship between your local Git and Jira's Git in the first place. But if there is — if you created the local Git by cloning Jira's Git, or if you have attached Jira's Git to your local Git as a remote — then the correct procedure was to git fetch in order to create remote-tracking branches in your local Git that are tied to Jira's Git. You could then have checked one of those out as a local branch.

If it's too late for that because you've created a local branch already, you can tie it to the remote-tracking branch after git fetch by saying

git branch -u origin/branchname branchname

The -u means "set-upstream" and ties the local branch, branchname, to the remote-tracking branch, origin/branchname (assuming that origin is the local name of the remote that designates Jira's Git). Please note that this is exactly what Git already told you to do when it said you should say

git branch --set-upstream-to=origin/<branch> feature/branch-name

You could have just done that and you'd be home by now.


Note that there are actually three branches in this story: the branch on Jira Git, the remote-tracking branch in your local Git, and the local branch in your local Git. The branch on Jira Git and the branch in your local Git will typically have the same name, let's say branchname; the remote-tracking branch in your local Git will typically have that name preceded by the origin name, let's say origin/branchname.

So, roughly speaking, the purpose of the remote-tracking branch is to act as a bridge between the other two:

  • When you say git fetch, you sync Jira's Git's branches down to your local remote-tracking branches. Therefore you don't usually need to tell Git how to tie a remote-tracking branch to the Jira Git; it already knows how to do that, because it was set up for you that way when you said git fetch.

  • When you say git checkout with a branch name that happens to match the name of a remote-tracking branch, Git assumes that what you really mean is, "Make a local branch and tie it to the remote-tracking branch of the same name." So it does that. That is why fetch and then checkout would have been the right thing to do originally. Instead, you made a local branch manually, and so it had no relation to the remote-tracking branch.

  • When you say git pull, you sync a Jira Git branch down through to the local remote-tracking branch to the corresponding local branch. The first step, involving the remote-tracking branch, just makes a copy; but the second step merges (by default) the remote-tracking branch into the local branch.

  • When you say git push, you sync the other way: the local branch is merged into the remote-tracking branch, which is then merged up into the corresponding Jira Git branch. Those merges are guaranteed to be fast-forward merges, because if they were not, Git would resist; you can overcome that resistance by using "force". If you say git push when the local branch is not tied to a remote tracking branch, you can tie it by adding the -u attribute: git push -u origin branchname is a common way to do a first push for a branch that you created locally, and after that you don't need the -u for that branch because the association has been made.

I have greatly simplified, but hopefully that's enough to give you a more accurate mental picture of what generally goes on.

Upvotes: 8

Related Questions