When working with Git, branching is a powerful feature that allows you to develop new features or fix bugs without affecting the main codebase. One common scenario is creating a new branch based on the latest state of the origin/master branch. This post will guide you through the steps to accomplish this quickly.
Step 1: Fetch the Latest Changes
Before creating a new branch, it's a good practice to ensure that you have the latest updates from the remote repository. You can do this by running:
git fetch origin
This command syncs your local repository with the remote, making sure you have the latest changes from origin/master.
Step 2: Create a New Branch
To create a new branch from origin/master, you can use one of the following commands:
git checkout -b new-branch-name origin/master
Or, if you prefer the modern switch command:
git switch -b new-branch-name origin/master
Replace new-branch-name with whatever you want to call your new branch. This command will create a new branch and switch to it immediately, allowing you to start working on your changes right away.
GitHub changed the default branch name from
master to main in 2020 as part of an effort to promote more inclusive language in software development. The term "master" has historical connotations that some people find problematic, particularly in the context of its association with slavery. So for the examples above, you should probably use
main instead of master for your command to work.Summary
Creating a new branch from origin/master in Git is simple and efficient. By using git checkout -b or git switch -b, you can quickly get started on your development tasks without disrupting the main codebase.
🔍. Similar posts
How to Set Your Local Branch to Track a Remote Branch in Git
30 Sep 2025
How to Add a Binary Folder Path to the PATH Environment Variable on macOS Using Vim
22 Jan 2025
The Simple Way to Run a Long Docker Command in Multiline
14 Jan 2025