Git Branches - List, Create, Switch To, Merge, Push, & Delete
Git Branches - List, Create, Switch To, Merge, Push, & Delete
Classes are running in-person (socially distanced) and live online. Secure your seat today
Search...
October 6, 2021
Read more in Git, Front-End Web Development, Web Development
Share
Git lets you branch out from the original code base. This lets you more easily work with other
developers, and gives you a lot of flexibility in your workflow.
https://www.nobledesktop.com/learn/git/git-branches 1/8
21/2/23, 11:35 Git Branches: List, Create, Switch to, Merge, Push, & Delete
Here's an example of how Git branches are useful. Let's say you need to work on a new feature for
a website. You create a new branch and start working. You haven't finished your new feature, but
you get a request to make a rush change that needs to go live on the site today. You switch back to
the master branch, make the change, and push it live. Then you can switch back to your new
feature branch and finish your work. When you're done, you merge the new feature branch into
the master branch, and both the new feature and rush change are kept!
git status
git branch
git branch -r
git branch -a
https://www.nobledesktop.com/learn/git/git-branches 2/8
21/2/23, 11:35 Git Branches: List, Create, Switch to, Merge, Push, & Delete
git pull
Push to a Branch
If your local branch does not exist on the remote, run either of these commands:
NOTE: HEAD is a reference to the top of the current branch, so it's an easy way to push to a
branch of the same name on the remote. This saves you from having to type out the exact name of
the branch!
If your local branch already exists on the remote, run this command:
git push
Merge a Branch
1. You'll want to make sure your working tree is clean and see what branch you're on. Run this
command:
git status
2. First, you must check out the branch that you want to merge another branch into (changes will
be merged into this branch). If you're not already on the desired branch, run this command:
https://www.nobledesktop.com/learn/git/git-branches 3/8
21/2/23, 11:35 Git Branches: List, Create, Switch to, Merge, Push, & Delete
Delete Branches
To delete a remote branch, run this command:
NOTE: The -d option only deletes the branch if it has already been merged. The -D option is a
shortcut for --delete --force, which deletes the branch irrespective of its merged status.
https://www.nobledesktop.com/learn/git/git-branches 4/8
21/2/23, 11:35 Git Branches: List, Create, Switch to, Merge, Push, & Delete
Web Development
Web Design Classes
Courses
Front-End Web
Development Certificate
108 hours $3,495
Full-Stack Web Development Certificate at Noble Desktop: live, instructor-led course available
in NYC or live online
https://www.nobledesktop.com/learn/git/git-branches 5/8
21/2/23, 11:35 Git Branches: List, Create, Switch to, Merge, Push, & Delete
Find Web Development Classes Near You: Search & compare dozens of available courses in-
person
Attend a web development class live online (remote/virtual training) from anywhere
Find & compare the best online web development classes (on-demand) from the top
providers and platforms
Train your staff with corporate and onsite web development training
Related Resources
https://www.nobledesktop.com/learn/git/git-branches 6/8
21/2/23, 11:35 Git Branches: List, Create, Switch to, Merge, Push, & Delete
Contact Us Location
Noble Desktop is today’s primary center for learning and career development.
Since 1990, our project-based classes and certificate programs have given
professionals the tools to pursue creative careers in design, coding, and beyond.
Noble Desktop is licensed by the New York State Education Department.
Enter your email to get tips, free giveaways, and more in our weekly newsletter.
https://www.nobledesktop.com/learn/git/git-branches 7/8
21/2/23, 11:35 Git Branches: List, Create, Switch to, Merge, Push, & Delete
https://www.nobledesktop.com/learn/git/git-branches 8/8