How to git fetch another branch after cloning one branch

I work on a system that automatically clones git using the --branch argument as follows:

git clone --branch master --depth 50 git@github.com:Something/Cool.git ~/Cool

And now I would like to click on another branch. I cannot figure out how to track remote access since git fetch and git pull do not have access to them.

+4
source share
2 answers

As a result, I changed the configuration for each branch (or branch) that I want to get. Expressed as an alias:

[alias]
    # Usage: git add-fetch-branch REMOTE BRANCH
    add-fetch-branch = !sh -c 'git config --add remote.$0.fetch "refs/heads/$1:refs/remotes/$0/$1"'
+1
source

I found a way to use add remote control.

So, after you select a separate branch, you set up a single branch to start with.

You can define a new remote

git remote add new_scope git@git.example.com:path/to.git -t NewScope/*

or

git remote add new_branch git@git.example.com:path/to.git -t new_branch
0
source

Source: https://habr.com/ru/post/1525560/


All Articles