Reputation: 1172
I've cloned a specific branch at GitHub (3.x), but origin was automatically set to a different branch (2.x).
I only want to work on the 3.x branch (never the 2.x branch). I'd rather use git pull origin than git pull origin/3.x.
What's the best way to change the default pull location?
Upvotes: 2
Views: 6878
Reputation: 1172
In this situation, there's no way to have "git pull origin" work to pull the 3.x branch because it's not the default branch of the remote repo.
After some experimentation, the best solution turned out to be this (issued from the parent directory):
git clone -b 3.x --single-branch [email protected]:user/reponame.git your_subdirectory
This prevents the other branch(es) from being cloned, and sets things up so "git pull" by itself, automatically pulls from the remote 3.x branch.
It also eliminates the potential errors with "git pull origin" or "git diff origin" (which would reference the default 2.x branch at the remote). Those commands don't work unless you reference the specific branch you've cloned.
Upvotes: 1
Reputation: 888
As I understand, you're trying to change your origin/branch
url but no need. Just check two different approaches for your issue.
$ git clone https://github.com/somegreatpath/somegreatproject.git
$ cd somegreatproject
Check what branch you are using at this point:
$ git branch
* 2.x
Check out the branch you want
$ git checkout -b 3.x origin/3.x
Branch 3.x set up to track remote branch 3.x from origin.
Switched to a new branch '3.x'
Confirm you are now using the branch you wanted:
$ git branch
* 3.x
2.x
If you want to update the code again later, run git pull
:
$ git pull
Already up-to-date.
And also you can change the origin
. Firstly, check current remote url:
$ git remote -v
* origin [email protected]:USERNAME/REPOSITORY.git (fetch)
* origin [email protected]:USERNAME/REPOSITORY.git (push)
Set new url
$ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
Verify that the remote URL has changed.
$ git remote -v
* origin https://github.com/USERNAME/REPOSITORYUSERNAME/REPOSITORY.git (fetch)
* origin https://github.com/USERNAME/REPOSITORYUSERNAME/REPOSITORY.git (push)
Hope, this is help!
Upvotes: 4