Git checkout checks out the remote branch
This article outlines the steps required to checkout a remote Git branch that does not exist in your local repository.
When collaborating as a team on a project, a developer can create a new branch and push it to a remote repository. Other developers must download the branch from the remote to access it locally.
So, how do you checkout a branch like this?
Check out a remote Git branch using a remote
Suppose we are collaborating on a project as a team, and one developer creates a test branch and pushes it to the remote, how do we check out the test branch locally?
First, we need to fetch from the remote repository. We will run:
$ git fetch
This will bring all the changes from the remote repository to our local machine. We can git branch
view all the branches available for checkout using the command as shown below.
$ git branch -v -a
This will give us all the remote and local branches available in the repository. To start working on the test branch, we will use git checkout
the command as shown below.
$ git checkout Test
By default, Git will switch to the testing branch and set it up to track the testing branch from our remote.
Checking out remote Git branches with multiple remotes
Again, we'll start by getting it remotely. However, this time, we'll specify a remote.
$ git fetch origin
We will then use git checkout
the command to create a local branch based on the remote branch.
$ git checkout Test
To checkout a remote branch that doesn't exist in our local repository, we need to fetch it from the remote first.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Git shows remote tracking branches
Publish Date:2025/04/03 Views:125 Category:Git
-
Branches on remote Git repositories are called remote branches. These are pointers to our remote repositories, including branches, tags, etc. Local branches only exist on each developer's local personal computer, but there is only one remot
View merged and unmerged branches in Git
Publish Date:2025/04/03 Views:96 Category:Git
-
This article discusses how to list merged and unmerged branches in Git. Git branches encourage convergent evolution of code. This is where we create a branch as a temporary space to work on a feature, and then merge the branch with its orig
The difference between Fork and Branch on GitHub
Publish Date:2025/04/03 Views:157 Category:Git
-
This article discusses the difference between Form and Branch on GitHub. In the context of coding, the current era relies more on collaboration. GitHub is one of the most commonly used collaboration tools. Forking and branching on GitHub ar
How to determine the current branch in Git
Publish Date:2025/04/03 Views:164 Category:Git
-
Git is a unique and popular version control system that is used by most of the software developers to keep an eye on the changes made in various applications and stay connected with other teams on the running projects. It helps large teams
Difference between Git Merge Origin/Master and Git Pull
Publish Date:2025/04/03 Views:195 Category:Git
-
This article outlines the differences between the git merge origin/master and git pull commands. These two commands integrate changes from a remote repository into the current local branch. However, each command's operation is unique and ha
Git Pull Origin branch overwrites Master branch
Publish Date:2025/04/03 Views:143 Category:Git
-
This article explains how we can revert the changes made to the master git pull origin branch branch after running the command . Assume that you have a master branch and a feature branch in your local and remote repositories . You pull chan
Git Pull and Merge Commands
Publish Date:2025/04/03 Views:56 Category:Git
-
In the vast world of version control systems, Git is the only fast, well-organized, in-demand, and easily accessible version control system that enables users to work on various projects simultaneously in an efficient manner without any col
Difference between Git Checkout --Track Origin/Branch and Git Checkout -B Branch
Publish Date:2025/04/03 Views:185 Category:Git
-
This article outlines the difference between the git checkout -b branch origin/branch and git checkout --track origin/branch commands. We use these two commands to check out remote branches in a Git repository. These two commands have the s
Rolling back to an old commit in a public Git repository
Publish Date:2025/04/03 Views:115 Category:Git
-
This article explains how we can roll back a public Git repository to an old commit. When using Git version control, we can go back to any desired point. Without further ado, let’s get into today’s agenda. Rolling back to an old commit