Branches
Git - Quick Reference
3 min read
Published Jun 19 2025
Guide Sections
Guide Comments
It is useful to create a branch to work on a new feature. Then you can develop and test the branch with the option of dropping the changes completely if it doesn't work out, or merging it back in to develop if everything is good.
List all branches:
Displays a list of all branches, with a *
next to the current branch.
Example output:
Create a new branch:
The -b
flag creates the branch.
The new branch will also be auto selected after creation.
This will create the branch with a starting point of whatever branch you currently have checked out. eg. if you have develop checked out and run the above command, the branches starting point will be the same commit as develop currently is on.
Select a branch
Make changes in the new branch as normal and commit as normal:
If you want to push the branch to the remote respository:
This only needs doing the first push, after that you can just use git push
.
If you want to just keep the branch locally, you can just use:
Merging this branch back in to develop
First switch to the develop branch:
Then merge the branch in to develop:
Then push these changes to develop:
Deleting the branch
First delete the remote one if you have one:
Then delete the local branch:
The -d
means delete the branch
Bringing in develop branch changes
If other changes have been done to the develop branch, where the feature branch originated from, and you are still working on the feature branch, then there are 2 ways you can bring the develop branch updates in to the feature branch.
1. Merge develop into your feature branch:
Make sure you have the feature branch selected:
Fetch the latest changes from the remote:
Merge the updated develop into the feature branch:
- Preserves history - you will see the merge commit.
- Good for teams that want to keep full context.
- Might require resolving merge conflicts if the same code has been edited in both branches.
- Edit each of the conflicted files and then add them to mark as resolved
git add thefilename.txt
. - Once all resolved complete the merge with
git commit
.
- Edit each of the conflicted files and then add them to mark as resolved
2. Rebase your feature branch onto latest develop:
Make sure you have the feature branch selected:
Fetch the latest changes from the remote:
Rebase your feature branch onto the latest develop
- Cleaner history - no merge commits.
- Rewrites your branch's commits as if they were made after the latest develop.
- Need to be careful if the feature branch has been shared with others.
- If there are merge conflicts:
- Fix the file and mark as resolved
git add thefilename.txt
. - Continue the rebase
git rebase --continue
. - Or abort the rebase
git rebase --abort
.
- Fix the file and mark as resolved
After either of the above methods:
If you have already pushed your feature branch to the remote and you rebased, you'll need to force-push:
If you merged, just do a regular push: