← Back to list

Git Episode 4: How to create a new branch with main branch files

Branches allow you to work on new features or fixes without touching the main code (usually the master or main branch).  Once your work is…

Shahmaruf Siraj Mugdho · 2025-12-08 18:35 · 0 claps · 0.9 min read
#github #branching-strategy #git-branching #git-clone
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Git Episode 4: How to create a new branch with main branch files

Branches allow you to work on new features or fixes without touching the main code (usually the master or main branch). Once your work is ready, you merge it back into the master branch.

✨ Part 1: Creating a New Branch

You have two ways to create a branch. Let’s look at both.

✅ Recommended Method: Clone → Create Branch

This is the cleanest and most common method.

Steps:

  1. Clone the repository:
git clone https://github.com/<owner-or-org>/<repo>.git
  1. Go into the project folder:
cd folderName
  1. Create a new branch (let’s say you want a create branch which name is “new”:
git checkout -b new
  1. Push your new branch to GitHub:
git push -u origin new

🎉 Your branch is now created!

✅ Bad Method (Not recommended) : Clone → Create Branch

  1. Download the project ZIP from GitHub and extract it.
  2. Open the folder in your terminal:
cd folderName
  1. Initialize Git:
git init
  1. Create a new branch:
git checkout -b new
  1. Add all project files:
git add .
  1. Commit the changes:
git commit -m "first commit after new branch"
  1. Connect to your GitHub repository:
git remote add origin https://github.com/<your-username>/<repo>.git
  1. Push the new branch:
git push -u origin new

🎉Your branch is created !!

Hit the clap button if this blog helped you. See you🙋‍♂️


메타데이터
post_id
a9e969eb0c95
slug
git-episode-4-how-to-create-a-new-branch-with-main-branch-files-a9e969eb0c95
url
https://medium.com/@shahmarufsirajmugdho/git-episode-4-how-to-create-a-new-branch-with-main-branch-files-a9e969eb0c95
canonical_url
https://medium.com/@shahmarufsirajmugdho/git-episode-4-how-to-create-a-new-branch-with-main-branch-files-a9e969eb0c95
author_url
https://medium.com/@shahmarufsirajmugdho
status
ok
fetched_at
2026-08-18 14:54:50