git pull witout git pull origin experiment
Getting started with github is easy. However when you create a branch and push it to remote then pulling from that
branch can cause problem to some people. Here is a run down of the problem and how to fix it.
First create a project called gitlab and push it to github.
> git branch -a * master remotes/origin/master
Above commands lists all the remote and local branches. At this point of time we have only master branch.
Let’s create a branch called experiment .
> git co -b experiment Switched to a new branch 'experiment'
Let’s push this branch to github .
> git push origin experiment Total 0 (delta 0), reused 0 (delta 0) To git@github.com:neerajdotname/gitlab.git * [new branch] experiment -> experiment
Let’s check if this branch has been pushed to github.
> git branch -a * experiment master remotes/origin/experiment remotes/origin/master
Not try doing git pull and you will get following error.
> git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.experiment.merge' in
your configuration file does not tell me either. Please
specify which branch you want to merge 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
configure the following variables in your configuration
file:
branch.experiment.remote = <nickname>
branch.experiment.merge = <remote-ref>
remote.<nickname>.url = <url>
remote.<nickname>.fetch = <refspec>
See git-config(1) for details.
Let’s see what config looks like .
> cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true [remote "origin"] url = git@github.com:neerajdotname/gitlab.git fetch = +refs/heads/*:refs/remotes/origin/*
Open a text editor and add three lines at the bottom of file. After modification the config file should look like this
> cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
url = git@github.com:neerajdotname/gitlab.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "experiment"]
remote = origin
merge = refs/heads/experiment
Now do a git pull .
> git pull Already up-to-date.
git pull worked. However if you don’t want to setup all this then you can use below given command.
git pull origin experiment
Update
Andy mentioned in the comment an easier way to enter required information in config file without actually editing the file.
git config branch.experiment.remote origin git config branch.experiment.merge refs/heads/experiment