![]() ![]() Again, on your local machine, run the git branch command, as shown below, to display all available branches, both local and remote.Īs you can see, when you run the git branch - all command, it shows that a new remote branch (Remote-branch) is available.Now, add a file named remote.txt with the text “This is remote file” in the Remote-branch by clicking on the Add file button.This is a collaborative process, so you have to imagine that someone else from your team performed this step.Ĭreated another branch (Remote-branch) in GitHub Navigate to the switch branch option by clicking on the master branch, as shown below. Next, create another branch named Remote-branch in the repository.Initially, you had only the master branch created in the repository, then you created a shanky-branch on your local machine.To retrieve all the latest changes to the remote branch on your local machine, you need to use the git checkout command again. But if any of your team members create a local branch on their machine using the same remote repository and update it, then you might end up missing those commits of the remote branch on your local machine. git checkout -b shanky-branch Creating and switching to a new branch How to check out branchesĮarlier, you learned how to create a new Git branch locally on your machine, and you switched to it using the git checkout command. The command below will create the branch (shanky-branch), then you can switch to this branch. git clone Cloning the repository on your machineĪfter successfully cloning the Git repository, go to the Petri directory and run the g it checkout command to create a new branch. Next, clone the repository to your home directory by running the git clone command below. This directory will hold the content of the Git repository that you will create. After you log in to the Ubuntu machine, switch to the home directory with the cd ~ command.Open your favorite SSH client and log in to the Ubuntu machine.Let’s clone the repository from GitHub that you already have set up. To create a new branch on your local machine, first, you will need to clone the repository to your machine. ? Y ou need to create a new branch other than the master branch to switch to another branch. Creating new branches and checking them outĮnough theory! Let’s jump into the practical and learn how the git checkout command lets you switch between two branches containing a different version of the code to test the functionality back and forth, all that without breaking the application running on the production code. ![]() This command allows you to fetch all the commits you are looking for in a particular branch in the working directory on your local machine to keep things in sync. ![]() Thankfully, to work with various branches, we have the aforementioned git checkout command, which allows you to work with multiple branches and repositories based on commits, files, and branches. Working within a big team of developers in a big organization requires you to handle and manage various branches and repositories. You can directly work on remote branches using the Git UI console, or work on your local machine and then later commit all your changes in the remote branch.
0 Comments
Leave a Reply. |