How To Clone And Create Remote Git Repository Branches Using Tortoise Git

Introduction

Here I will discuss on how to clone and create branch using tortoise git client. I assume here that a master branch already exists in the remote git repository. I will show you here how to clone the master repository in your local system using git client. You can also use the command line tool to clone the remote repository in your local system. Once cloning is done then I will show you how to create a development branch and a feature branch.

For this example, let’s say I have a master branch for the repository django-mysql. So I will create development and feature branches from this repository. First I will create development branch from the master branch then I will create feature branch from the development branch.

Before you proceed further make sure you have the tortoise git client installed on your system.

Git Repository Clone

To clone the repository you need to do a right click on a particular folder where you want to clone your repository. For example, I want to clone the repository in C:\Git_Projects folder, so I did right-click after going inside this folder and you will see the options similar to the below image.

clone and create branch tortoise git client

Now when popup opens, you need to put the git repository URL (https://github.com/roytuts/django-mysql.git) as highlighted in the below image. Don’t try to clone this repository, it’s my private repository and it is used here for example explanation. You can also use command git clone https://github.com/roytuts/django-mysql.git in your command line tool to clone the remote repository.

The local system’s folder is already selected where you want to download your remote repository. For the Branch, you need to select the checkbox and give the branch name (for example, master, development, feature/feature-1234, etc.) but here I am cloning master branch so I have kept it blank because by default master branch will be downloaded. Even you can change the local folder name django-mysql to other name. For example, you can put django-mysql-master to make it more readable. Finally you need to click on Ok button.

clone and create branch tortoise git client

Once the remote repository gets cloned, you will see the local folder in your directory as shown in the below image.

clone and create branch tortoise git client

Create Remote Branch in Git Repo

So you have successfully cloned your repository into your local system. Now let’s say you want to create a development branch because it is not a good idea to start development on your master branch. If anything goes wrong it may mess up with your master branch. Master branch should always be kept stable. To create a new branch, do a right click on the django-mysql folder and follow the options: TortoiseGit -> Create Branch.

clone and create branch tortoise git client

Once you click on Create Branch option you will see a popup with several options as shown in the below image. You need to put the branch name, here I have put development. Then there is an option called Base On, so I am using the default one (HEAD master). You can also put description.

clone and create branch tortoise git client

You can choose one commit that base on:

  • HEAD – Current commit checked out.
  • Branch – The latest commit of chosen branch.
  • Tag – The commit of chosen tag.
  • Commit – Any commit, you click … to launch log dialog to choose commit. You also can input commit hash, or friendly commit name, such as HEAD~4.

The Force option will override the branch if you have the same branch exists.

If you want your working tree to be switched to the newly created branch automatically, use the Switch to new branch/tag checkbox. But if you do that, first make sure that your working tree does not contain modifications. If it does, those changes will be merged into the branch working tree when you switch.

Finally click on Ok to create the branch. So your branch has been created.

Unless you checked the “Switch to new branch” checkbox in the Create Branch dialog your working directory is still the master branch. To switch to the newly created branch you right click and pick the Switch/Checkout menu item. And then select your development branch and click Ok button.

clone and create branch tortoise git client

Now you need to push this development branch to remote repository because it does not exist in the remote repository. Do a right click on your django-mysql folder and go to option TortoiseGit -> Push to push the branch. Next you will see the below popup where your local branch is development and you may also want to keep the same name in your remote repository, so keep it blank and hit Ok button.

clone and create branch tortoise git client

So your remote development branch is created successfully.

clone and create branch tortoise git client

Now you can also clone development branch in the same way you did earlier for master branch or you can continue working on development branch. For example, as shown in the below image.

clone and create branch tortoise git client

Now you can create feature branch from your development branch in the same way you did development branch from master branch. Feature branches are useful when multiple team members are working on individual feature. So for each developer there will be each separate feature branch from the development branch.

That’s all. Hope you got an idea how to create and clone remote branches and push the changes using tortoise git client.

Leave a Reply

Your email address will not be published. Required fields are marked *