Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Remote for Only One Branch?

Tags:

git

I need to work with a remote repository and I have it set to a local branch but I need to type the URL every time I want to update the branch from the remote repo. Is there a way to change the origin only for that one branch? So to update the branch I don't have to use the URL.

What I currently do:

git fetch https://github.com/username/repo branch:my-local-branch

But I'd rather just do something like:

git fetch my-local-branch

Where the above would fetch from https://github.com/username/repo.

like image 212
razr32 Avatar asked Dec 05 '25 06:12

razr32


1 Answers

origin is just an arbitrary name that happens to be the conventional default. But you can add as many remote repositories as you like. Just use git remote add username https://github.com/username/repo, then you can configure the upstream of your local branch with git branch --set-upstream-to=username/branch my-local-branch.

From then on you can use git pull or git pull --rebase from your my-local-branch or git fetch username/branch to fetch the remote branch from that repository.

like image 89
Vampire Avatar answered Dec 07 '25 21:12

Vampire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!