JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Switch remote Git branch

Author:JIYIK Last Updated:2025/04/04 Views:

This article will show you how to switch remote Git branches using checkoutthe command. The version control tool that allows you to support and manage variable versions of your application in a team of members is the Git version control tool. When your application encounters new updates, Git prefers to roll back those changes to the previous version and merge the two versions into a new version.

As we know, in Git we have branches that allow us to work in multiple environments, with different users working at the same time. In Git, we have a master branch which is the main branch that holds our security code, and this code is placed when our application is almost ready for production. Also, when we want to update the application, we can add more commits to this branch. This approach is ideal for minor commits, but for big commits, it is not so suitable. For major commits, you can use other branches as well.

To create and use a new branch, we use the following command:

# create a new branch
git branch branch-name
# change environment to the new branch
git checkout branch-name

In the above command, we have created a new branch. We will check out the branch and then add new changes; after that, we will merge it with the master branch and push it to the latest remote branch. But imagine if the remote branch already exists and we have to pull the branch and the related work with all its changes to our local branch, then we will run git checkout remote branch.

In Git, checkoutit can be explained as the act of switching between various versions of a target unit. The command used for checkout in Git is that git checkoutit operates on three well-defined units: files, commits, and branches. git checkoutIt can also be used to view old commits, but almost all of the targets of this document will be switching operations on branches.

If we say another developer on the same repository has created a remote branch, and we want to pull that branch that other developer has created. Here is how we have to do it:


List Git's available branches

The result of the following command will show a list of branches available for switching. For remote branches, there will be a remote/originprefix used with them.

git branch -a

Get all Git remote branches

With the help of the following command, we will fetch the remote branch from its repository. originis the name of the remote branch we are targeting. If we have a upstreamremote name, we can refer to it as git fetch upstream.

git fetch origin

Pull changes from a Git remote branch

As we all know, we can't make changes directly on the remote branch. So here we need a local working copy. With the help of the remote branch, we will switch to the branch we are interested in; here is how we do it.

git checkout -b test origin/test

Previous:Git shows remote tracking branches

Next: None

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.

Article URL:

Related Articles

Git shows remote tracking branches

Publish Date:2025/04/03 Views:126 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:97 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:165 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:196 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:144 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

Rolling back to an old commit in a public Git repository

Publish Date:2025/04/03 Views:116 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

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial