Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.4k points)

I'm not a git master, but I have been working with it for some time now, with several different projects. In each project, I always git clone [repository] and from that point, can always git pull, so long as I don't have outstanding changes, of course.

Recently, I had to revert to a previous branch and did so with git checkout 4f82a29. When I was again ready to pull, I found that I had to set my branch back to master. Now, I can not pull using a straight git pull but instead, have to specify git pull origin master, which is annoying, and indicates to me that I don't fully understand what is going on.

What has changed which does not allow me to do a straight git pull without specifying origin master, and how to I change it back?


-bash-3.1$ cat config


    repositoryformatversion = 0

    filemode = true

    bare = false

    logallrefupdates = true

[branch "master"]

[remote "origin"]

    url = [email protected]:user/project.git

    fetch = refs/heads/*:refs/remotes/origin/*

UPDATE 2: To be clear, I understand that my original method may have been incorrect, but I need to fix this repo so that I can simply use git pull again. Currently, git pull results in:

-bash-3.1$ git pull

You asked me to pull without telling me which branch you

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

your configuration file does not tell me either.  Please

name which branch you want to merge on the command line and

try again (e.g. 'git pull  ').

See git-pull(1) for details on the refspec.

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

configure the following variables in your configuration


    branch.master.remote = 

    branch.master.merge = 

    remote..url = 

    remote..fetch = 

See git-config(1) for details.

I can tell git pull which branch to merge, and it works correctly, but git pull does not work as it did originally before my git checkout.

1 Answer

0 votes
by (27.5k points)

Here's a simple method to add the upstream reference:

$ git pull origin master

$ git push -u origin master

This command will add the same information to your .git/config. 

Browse Categories