Mamun
Mamun

Reputation: 1

How to clone all remote branches in Git lab?

I have a master and a development branch, both pushed to Git lab. I've cloned, pulled, and fetched, but I remain unable to get anything other than the master branch back.

I'm sure I'm missing something obvious, but I have read the manual and I'm getting no joy at all.

Upvotes: -1

Views: 4766

Answers (3)

Ansver like above, but for me do not work via "grep remotes"(I attached screen).. So: git clone YOUR-URL; cd to folder or press TAB :) for branch in git branch -r |grep "origin" |grep -v HEAD | grep -v master; do local_branch=$(echo "$branch" | sed '/^.*//!d; s///;q'); git checkout $branch; git branch $local_branch ; done; git branch

Some description: sed '/^.*//!d; s///;q'
to do from "origin/PROD_SERVICES" this "PROD_SERVICES"

enter image description here

Upvotes: 0

CodeWizard
CodeWizard

Reputation: 142532

When you clone you have all the information downloaded to your .git folder

To view all the branches use this:

git branch -a

To checkout locally all your branches use this

# loop over all the branches check them all out
for branch in `git branch -r | grep remotes | grep -v HEAD | grep -v master `; do
git checkout $branch

done

What does the script do?

git branch -r
get a list of all the remote branches

| grep remotes The branch names are : 'remotes/origin/' so this will remove the remotes from the branch names

| grep -v HEAD
Filter HEAD from the branches list

| grep -v master
Filter `master`` from the branches list since you already have it locally

Upvotes: 0

qräbnö
qräbnö

Reputation: 3031

You see your development branch in Gitlab?

What shows

git branch -a

?

You can "activate" your development branch with

git checkout development

Have fun.

Upvotes: 3

Related Questions