Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab Pull a branch to the local machine

Tags:

git

gitlab

I want to copy a branch of the online repository (Gitlab) to my local machine. Let's assume the branch is called "Version1" - then I want to copy this branch to a new branch called "Version2" on my local machine. Because I dont want to overwrite this branch later. The problem i got is the following: Every time I create a new branch on my local machine it is a copy of the branch that I was before.

git pull origin Version1

does not work as i want.

Would be great if someone could help.

like image 711
lars111 Avatar asked Oct 19 '22 15:10

lars111


1 Answers

You can create a local branch on your machine that is based off of the Version branch.

Use the checkout command with -b.

First switch to the branch you want to "copy":

git checkout Version1

Next, create your own branch that is based off of Version1:

git checkout -b Version2

Now, when you create commits while on the Version2 branch, your local copy of Version1 will remain unchanged.

Here is a good article to learn more about branching.

like image 196
Jonathan.Brink Avatar answered Oct 31 '22 12:10

Jonathan.Brink