In this post, I’ll walk you through how to create a Git branch from a parent branch, pull the latest changes, commit your code, push it to the remote repository, merge branches, and finally make sure everything stays up to date. I’ll explain each step in a simple and practical way.
Let’s get started 🚀
1️⃣ Switch to the Parent Branch and Fetch Latest Changes
First, move to the parent branch (usually main or develop) and fetch the latest updates from the remote repository.
git checkout branch-name
git fetch origin
Now pull the latest changes to make sure your parent branch is up to date:
git pull origin branch-name
2️⃣ Create a New Branch from the Parent Branch
Once your parent branch is updated, create a new feature branch from it:
git checkout -b new_branch_name(feature/login)
This command creates a new branch and switches to it at the same time.
3️⃣ Make Changes and Commit Your Code
After making your code changes, check the status:
git commit -m "commmit msg"
4️⃣ Push the Branch to Remote Repository
To push your newly created branch to GitHub:
git push origin branch_name(in which you have push)
5️⃣ Merge Parent Branch into Your Feature Branch
Before pushing or raising a pull request, always merge the latest parent branch into your feature branch.
git merge branch_name(which branch you have to merge)
6️⃣ Always Pull Before You Push
To avoid conflicts, make it a habit to pull the latest changes before pushing your code:
git pull origin branch-name

Top comments (0)