+1 vote
1 view
in Devops and Agile by (25.5k points)

I create a new branch in Git:

git branch my_branch

Push it:

git push origin my_branch

Now say someone made some changes on the server and I want to pull from origin/my_branch. I do:

git pull

But I get:

You asked me to pull without telling me which branch you

want to merge with, and 'branch.my_branch.merge' in

your configuration file does not tell me, either. Please

specify which branch you want to use on the command line and

try again (e.g. 'git pull <repository> <refspec>').

See git-pull(1) for details.

If you often merge with the same branch, you may want to

use something like the following in your configuration file:

    [branch "my_branch"]

    remote = <nickname>

    merge = <remote-ref>

    [remote "<nickname>"]

    url = <url>

    fetch = <refspec>

I learned that I can make it work with:

git branch --set-upstream my_branch origin/my_branch

But why do I need to do this for every branch I create? Isn't it obvious that if I push my_branch into origin/my_branch, then I would want to pull origin/my_branch into my_branch? How can I make this the default behavior?

1 Answer

0 votes
by (42.6k points)

As per git version, 1.8.0  follow this command

 git branch --set-upstream-to origin/my_branch

Or you can use 

git branch -u origin/my_branch

From official announcement of v 1.8.0 

* It was tempting to say "git branch --set-upstream origin/master", but that tells Git to arrange the local branch "origin/master" to integrate with the currently checked out branch, which is highly unlikely what the user meant.  The option is deprecated; use the new "--set-upstream-to" (with a short-and-sweet "-u") option instead. 

Refer announcement from:-http://git.661346.n2.nabble.com/ANNOUNCE-Git-v1-8-0-rc1-tc7568792.html

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...