Andrea Daly : Pull from an existing Remote Feature Branch via Single Branch Clone

[make dir and cd into or cd into existing dir]

mkdir <project-dir>

cd <project-dir>

 

[clone repo and cd into newly cloned project dir]

git clone  -b <remote-feature-branch>  --single-branch  <remote-ssh-url>

[example: git clone -b new-feature-a --single-branch git@gitlab.com:andrea-sample-resources/git-lab-examples.git]

ls

cd <project-dir>

 

[verify local branch is created, compare to remote verify tracking]

git branch

git branch r

git branch -vv

 

[make and commit changes]

[push local changes to remote branch. Branch is already tracked so only need to :]

git push

 

[If subsequently need to track another remote branch:]

git remote set-branches --add origin <remote-feature-branch>

[Example: git remote set-branches --add origin new-feature-b]

git fetch origin

git checkout --track origin/<remote-feature-branch>

[Example: git checkout --track origin/new-feature-b]

 

[make and commit changes]

git push

 

 

https://careerkarma.com/blog/git-clone-specific-branch/#:~:text=You%20can%20clone%20a%20specific,to%20fetch%20them%20later%20on .