How do you get git to always pull from a specific branch?

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?

UPDATE:

-bash-3.1$ cat config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
[remote "origin"]
    url = git@github.com: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
file:

    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 .


Under [branch "master"] , try adding the following to the repo's Git config file ( .git/config ):

[branch "master"]
    remote = origin
    merge = refs/heads/master

This tells Git 2 things:

  • When you're on the master branch, the default remote is origin.
  • When using git pull on the master branch, with no remote and branch specified, use the default remote (origin) and merge in the changes from the remote master branch.
  • I'm not sure why this setup would've been removed from your configuration, though. You may have to follow the suggestions that other people have posted, too, but this may work (or help at least).

    If you don't want to edit the config file by hand, you can use the command-line tool instead:

    $ git config branch.master.remote origin
    $ git config branch.master.merge refs/heads/master
    

    If you prefer, you can set these options via the commmand line (instead of editing the config file) like so:

      $ git config branch.master.remote origin
      $ git config branch.master.merge refs/heads/master
    

    Or, if you're like me, and want this to be the default across all of your projects, including those you might work on in the future, then add it as a global config setting:

      $ git config --global branch.master.remote origin
      $ git config --global branch.master.merge refs/heads/master
    

    git branch --set-upstream master origin/master
    

    This will add the following info to your config file:

    [branch "master"]
        remote = origin
        merge = refs/heads/master
    

    If you have branch.autosetuprebase = always then it will also add:

        rebase = true
    
    链接地址: http://www.djcxy.com/p/41680.html

    上一篇: 我如何放弃远程更改并将文件标记为“已解决”?

    下一篇: 你如何让git总是从特定的分支中拉出来?