Create new branch with git command line
Using the git terminal below are steps in creating a new branch and pushing it to remote repository

Software engineer focusing on PHP, JavaScript, HTML, CSS, CI/CD, GitHub, AWS, Azure & Magento Commerce. I enjoy code for good projects, tech, gym, nature, travel, fried chicken, and coffee.
All my articles are educational only from my experience.
Feel free to connect.
Say you have made some changes on a branch currently but dont want to put these changes on this branch but instead on a new branch
First check your current status of your git
git statusStash your changes, don't worry they wont be lost
git stashCheck your current branch status
git branch -aCreate a new branch, this will copy from current branch
git branch <ADD YOUR NEW BRANCH NAME>Check your current branch status, see if your new branch exists
git branch -aSwitch to this new branch
git checkout <ADD YOUR NEW BRANCH NAME>Check your current branch status
git branch -aYour current branch will be green like so

Bring your changes back that you stashed before
git stash popYou will have your changes back now, confirm this by running
git statusAdd all your changes for commit by running
git add .Add a commit message
git commit -m "<ADD YOUR COMMIT MESSAGE>"Push your changes, setting the new branch to root of your directory
git push --set-upstream origin <ADD YOUR NEW BRANCH NAME>Your changes will now be on your remote branch
Hope this helped you, if this didn't please comment and I will try help you.
Remember to like, post a comment and share.
Happy Coding 🙂
Asrin 🤙
Shameless Plugs
- Join me and invest commission-free with Freetrade. Get started with a free share worth £3-£200.
- Start a blog on Hashnode
- Transfer money internationally with Wise
- Join coinbase with my and you will earn some free crypto as well
If this helped you consider buying me a coffee 🙂






