Skip to content

Instantly share code, notes, and snippets.

@zacharyabresch
Last active April 12, 2018 16:36
Show Gist options
  • Save zacharyabresch/7e3c999886c41cdfca15c93c104617df to your computer and use it in GitHub Desktop.
Save zacharyabresch/7e3c999886c41cdfca15c93c104617df to your computer and use it in GitHub Desktop.
Proposal for branch deletion process & workflow

Deleting Branches After Merging

Recently, I completed a pull request and merged my branch into staging once approved. In the past, I've seen some developers delete their branch after merging and others don't do this. I've historically been pretty bad at this myself and was wondering what the team thinks about this.

Personal Opinion

I think that deleting branches after a successful merge should be a practice followed by everyone on the team. There are a lot of good reasons to do this and there's really no reason not to, IMHO. Currently, on staging, there are 229 branches! (git branch --all | wc -l) Of those 229, 69 of them show as "merged" (git branch --all --merged | wc -l). Running git branch --all is far less useful in this state.

Suggested workflow

This is where I'm also looking for team input. The easiest thing would be to always click the Delete Branch button after merging on Github's web interface. Then it would just be a matter of running git prune locally to remove deadwood. If you're cool, you'd:

  • git merge /your/branch/name
  • git branch -dr /your/branch/name

This could also be something we trigger off of a successful pull-request (i.e. ready to merge) with automation but that's a bit outside my wheelhouse.

Eventually, we'd want to run a git --remote prune origin to purge any deadwood on the remote and devs could git fetch --prune to sync up.

@chrisvariety
Copy link

Agreed and I do this myself already

@zacharyabresch
Copy link
Author

zacharyabresch commented Apr 12, 2018

BTW, I'm 👀 at myself here ... I haven't deleted a branch since I started. 😨

@zacharyabresch
Copy link
Author

I lied ... I just deleted one. 😸

@zacharyabresch
Copy link
Author

zacharyabresch commented Apr 12, 2018

Interesting ... you can't create Gists as an organization. Looks like a common solution is having a separate repository for gist-esque files. Not sure how I feel about that but it would be nice to have these associated to our organization. Plus, we could treat "approving" or "declining" proposals similar to pull requests and only approved ones get merged into master. Thoughts?

@mdeltito
Copy link

Agree with all this, I'm not great about deleting my own branches and I don't think I've ever cleaned up my local repo.

git merge /your/branch/name

The only thing I'd suggest is that we always "Squash and Merge" PRs into staging on GitHub (or manually with the same outcome) if possible.

@zacharyabresch
Copy link
Author

Sure, that's definitely a discussion we can have. I guess, since I always rebase staging into my branches, I haven't bothered with "Squash & Merge". I have some ideas on rebasing, squashing, and commit messages so maybe we'll kick off a larger "All thing git" discussion.

@zacharyabresch
Copy link
Author

zacharyabresch commented Apr 12, 2018

For completion, merge & squash from CLI: git merge --squash /your/branch/name/

Personally, I'd do this with git rebase -i and squash manually but we can decide as a team which we prefer. Better than no decision. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment