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 = [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 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
.
You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.
just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.
A safe approach is to create a local branch (i.e. xyz) first and then pull the remote branch into your locals. Here is the syntax that could pull a remote branch to a local branch. Perfect! I just didn't know that syntax: git pull {repo} {remotebranchname}:{localbranchname}.
Git Pull Doesn't Do A Git Fetch.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With