About this question
How can you switch to a branch that exists on a remote Git repository? What commands should you use to fetch and check out a remote branch locally? Let’s explore the steps to do it!
How can you switch to a branch that exists on a remote Git repository? What commands should you use to fetch and check out a remote branch locally? Let’s explore the steps to do it!
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask DevOps Expert
Answered on Apr 2, 2025
If you want to work on a branch that exists on a remote Git repository, you need to fetch it first and then check it out locally. Here’s how you can do it step by step:
1. Fetch the Remote Branches
Before checking out a remote branch, you should update your local repository with the latest remote branches:
git fetch origin2. List All Remote Branches
To see available remote branches, run:
git branch -rThis displays all branches available on the remote repository.
3. Check Out the Remote Branch Locally
Once you know the branch name, check it out using:
git checkout -b my-branch origin/my-branch4. Alternative: Use git switch (Newer Versions of Git)
For Git 2.23+, you can use switch instead of checkout:
git switch --track origin/my-branchThis is the recommended way in newer Git versions.
Final Tips:
git checkout my-branch Use git pull after switching to ensure your branch is up to date.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common DevOps interview questions, answered
Guides, tips and career advice on DevOps from JanBask experts.
DevOps How to Become a DevOps Engineers: Learning Path, Critical skills & More
Looking for answer to how to become a DevOps engineer in 2025? Here is the detailed article about DevOps career path, DevOps…
DevOps Top 50+ Jenkins Interview Questions And Answers For 2025
Here are the Top 50 Jenkins interview questions frequently asked in top MNCs which will help you land an ideal job! These…
DevOps Best 37 DevOps Tools To Learn And Master In 2025: Docker, Git & More
Want to know what are Devops tools and their uses? Or looking for the best DevOps list for automation, monitoring, & development?…
DevOps DevOps Engineer Job Description: Roles and Responsibilities [2025 Updated]
Discover the essential roles and responsibilities of a DevOps Engineer by exploring the detailed DevOps job description, and…