I want to know if I can fetch a Git branch from a remote repo, but store it under a different name in my local repo. It happens to be the master
branch of the remote repo, but I'd like it to show up as, say, featureX
.
I know it's possible to push <remote> local_name:remote_name
(on the initial push) to change the name that will show up in remote. Basically I want to do that in reverse, without the other repo having to rename its master
branch. Any configuration options required to make the future fetches/pulls behave correctly with the featureX
name would be appreciated as well.
To be precise, renaming a remote branch is not direct – you have to delete the old remote branch name and then push a new branch name to the repo. Step 2: Reset the upstream branch to the name of your new local branch by running git push origin -u new-branch-name .
Git fetch commands and options Fetch all of the branches from the repository. This also downloads all of the required commits and files from the other repository. Same as the above command, but only fetch the specified branch.
Use git branch -a (both local and remote branches) or git branch -r (only remote branches) to see all the remotes and their branches. You can then do a git checkout -t remotes/repo/branch to the remote and create a local branch. There is also a git-ls-remote command to see all the refs and tags for that remote.
git fetch <remote>
git checkout -b <local-branch> <remote>/<remote-branch>
Alternatively if you already have <local-branch>
and just want it to track <remote-branch>
:
git checkout <local-branch>
git branch -u <remote>/<remote-branch>
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