Git: putting your new feature out into the world.


A git workflow to put a local feature out in the wild, then tidy up after yourself.


Zak Varty


December 13, 2022

git logo. This is a red-orange square with rounded corners, it is rotated by 45 degrees so that it is standing on one corner and has a cut-out design representing a branching graph.

So you’ve added a new feature to your project. You were responsible and didn’t do this in the main branch. Congrats on being responsible, have some brownie points.

Now how the heck to you get everything moved across and delete your new-feature branch?

1. Check that your local main is up to date.

Be in the main branch and pull any changes to the remote main branch.

git checkout main 
git pull origin main

This might require you to resolve some merge conflicts, but these should be pretty straightforward if you are following a branch-and-merge workflow.

2. Check that you remote new-feature is up to date.

We might mess things up while merging. Let’s make sure that if that happens we can get back to this good position with our new feature.

git checkout new-feature
git status

If needed: add, commit and push.

3. Merge any changes to main into your local new-feature branch

Next, we will make sure we have any changes to main moved across to our local new-feature branch.

git merge main

This might again require resolving some merge conflicts. Keep calm and take tea breaks are required.

4. Commit and push to remote.

Now that we have our local new-feature branch compatible with the remote main branch, lets push that to the remote.

git commit -m "merge changes to main in preparation for PR"
git push

5. Open a pull request on Github

Wait for someone to review approve your new feature (or wait a few hours/days and do it yourself for a solo project).

6. Delete the local branch

git checkout main
git branch --delete new-feature

7. Delete the remote branch

git push origin --delete new-feature

On older versions of git (< 1.7.0) you might need to use the alternative syntax below. This is effectively pushing nothing to the new-feature branch of origin.

git push origin :new-feature

Bam! You did it! Your new-feature is out there in the wild, making the world a marginally better place.