Git - Not Something We Can Merge
Tags: development, git, github, branching
Published: 2020-08-30 19:48:34

---
title: "Git - Not Something We Can Merge"
published: true
description: "Merging a branch to main repository responds with not something we can merge error. We look the causes and branching name conventions and restrictions"
tags: ["development", "git", "github", "branching"]
canonical_url: https://kags.me.ke/post/git-not-something-we-can-merge/
---

I use Git for version control. My workflow is simple; create branch from the main branch, make changes on the new branch, commit the changes and merge the changes to the main branch. I have aliased the `git` command to `g` and combine the commands in a single line in the form `g checkout master;g merge branch-name;` and it works.

It was therefore a surprise when I ran `g checkout master;g merge add_progress;g push;g checkout add_progress` and Git  responded with **merge: add_progress - not something we can merge**. Being a moderate git user, my first thought was I had used a restricted word in the branch name. Could I have typed the branch name wrongly? I rechecked the branch name and re-ran the command--same result.

Before searching the cause of the error, I replaced the branch name with the commit ID for the merge command. That worked without raising the error. So, what was wrong with my branch name? Does Git have any restrictions on branch names?

### It Could Be a Silly Typo

Turns out, the [error can arise from a typo in the branch name](https://stackoverflow.com/questions/16862933/how-to-resolve-gits-not-something-we-can-merge-error/16862934#answer-16862934). Taking a deeper look on my Git command, I realized I had typed an underscore (_) for the branch name (`add_progress`) instead of a dash (`add-progress`), damn it! 

I could not figure out why the Git team decided against a simplified error like **merge: <branch_name> - invalid branch name**. This begged the question, are there any restrictions or guidelines on branch naming?

### Git Branch Naming Conventions

While conventions are good for consistency, no single common convention exists for branch naming. Different teams adopt different styles for naming their Git branches. 

Some teams prefer prefixing branch names with (first and last names followed by a forward and branch description separated by hyphens)[https://dev.to/g_abud/advanced-git-reference-1o9j]. 

Others break down features into subtasks and name branches based on [feature-subtasks](https://blog.kowsheek.com/git-branch-naming-conventions-for-the-real-world/). This would have a `billing-module` have branches names such as `billing-module-setup`,  `billing-ui-changes` and  `billing-database-migration`.

[Change types]() as a prefix for naming branches (`new-feature/twitter-feed`, `refactor/homepage/carousel`, `fix/twitter-feed/number-of-tweets`) is adopted by other teams. Using this style and separating the change type and feature with a slash (/) makes Git create separate folders in `git/refs/heads/` directory of your repository.

 [BEM (Block Element Modifier)](http://getbem.com/) is another convention used in naming Git branches. This style takes [`reason__details--tag`](https://codeburst.io/let-the-branch-name-do-all-the-talking-in-git-e614ff85aa30) format.  Reason is the change type, details provide a short description of the change while the tag is optional. When the tag is available, it may refer to an external tracker or other extra details.

### Branch Naming Restrictions

[Restrictions on naming](https://wincent.com/wiki/Legal_Git_branch_names) branches borrows from [restrictions in reference names](https://git-scm.com/docs/git-check-ref-format). Names cannot: 

1. begin with a dot (`.`) or end with the sequence `.lock`.

1. have two consecutive dots `..` anywhere.
1. have ASCII control characters, space, tilde (`~`), caret (`^`), or colon (`:`) anywhere.
1. have question-mark (`?`), asterisk (`*`), or open bracket (`[`) anywhere. 
1. begin or end with a slash (`/`) or contain multiple consecutive slashes 
1. end with a dot (`.`).
1. contain a sequence (`@{`).

Git ignores a backslash (`\`) in a name. For example `g checkout -b po\le` will create a branch  named `pole`.

An opening bracket `(` in a name produces an incomplete command prompt (`>`). You have to press **Ctrl+C** to revert to your  normal terminal prompt. Maybe the `(`  has a special meaning to Git.

![Alt "opening bracket in branch name produces incomplete command prompt"](https://dev-to-uploads.s3.amazonaws.com/i/j4tzvc7a1okfo26md81a.png)

Every cloud has a silver lining. Without the error, I would not have taken the effort to learn how others handle  Git branching conventions and naming.

### Additional Resources 

- [Git Branch Naming Convention](https://dev.to/couchcamote/git-branching-name-convention-cch)
- [Git Style Guide](https://github.com/agis/git-style-guide)
- [How to organize your git branches](https://dev.to/hardkoded/how-to-organize-your-git-branches-4dci)
- [Understanding the GitHub flow](https://guides.github.com/introduction/flow/)
- [Git Branch Naming Conventions](https://allenan.com/git-branch-naming-conventions/)