How to Rename a Branch Locally and Remote in Git

This took some googling, so I thought I would document my findings here.


If you’re already on the branch you’d like to rename, just run:

git branch -m new-name

If you’re on say master, and you have a branch you want to rename now but no checkout, run:

git branch -m old-name new-name

Now that you’ve taken care of your local branch, there’s the unfinished business of mending your remote branch with renaming.


If you use Github or Gitlab (or whatever) you’re going to want to remove the old-name branch and push the new-name branch:

git push origin :old-name new-name

And finally, push to reset the upstream branch so your local and remote branches are up-to-date:

git push origin -u new-name

How to Move Existing, Uncommitted Work to a New Branch in Git

So here’s a new one for ya.

I was working on a branch all day, closed the laptop, went home and fell asleep. Nothing out of the ordinary. The next day, I awoke, and upon returning to work, immediately began working on a new problem.

The issue arose when I discovered to my horror that I was still on the same branch from yesterday! *Gasp*

Lest we forget, we have Git at our disposal — so I take a breath and dive in:

git status

This will probably return a list of changes not staged like this:

On branch fix-from-yesterday
Your branch is up to date with 'origin/fix-from-yesterday-'.

Changes not staged for commit:
(use "git add …" to update what will be committed)
(use "git checkout -- …" to discard changes in working directory)
modified: project/api-v4.php
modified: web/assets/js/some-project/package.json

Now that we have a pulse on things, we can do this:

git checkout -b new-branch-of-changes-for-today

This will leave your current branch as is, create and checkout a new branch and keep all your changes. You can then make a commit with:

git add <the files you want commit>

and finally, commit to your new branch with ol trusty:

git commit -m "Make sure your description is short and sweet"

And there you have it! According to git-checkout documentation, -b and -B are interchangeable. Here’s the rub:

Specifying -b causes a new branch to be created as if git-branch[1] were called and then checked out. In this case you can use the --track or --no-track options, which will be passed to git branch. As a convenience, --track without -b implies branch creation; see the description of --trackbelow.

If -B is given, <new_branch> is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of

Thoughts on Microsoft Acquiring Github

The Octocat is dead, long live the Octocat.

So, this just happened. It’s official. Microsoft will acquire GitHub for $7.5 billion in Microsoft stock. Quite the price tag.

I’ve used Github for years. I’m sure many of you have too. It’s really a remarkable place. Millions of users, all humming at their own pace, piecing code together. Hundreds of millions of unique repositories of codebases, open-source projects, communities, and amazing software.

I’m a little concerned and sidewinded by the sheer magnitude of this story. Github has largely been hailed as the neutral library of the world’s code. Communities and enemies alike have been forged in fiery maelstroms of pull requests and pithy “+1” comments on issues. But, for the most part, Github has been a great product. Apart from the occasional server downtime or DDoS attack from China, it’s been great. And personally, the community has largely been life-changing for me. If it weren’t for the community, I probably wouldn’t be where am now.

I can say with certainty, I’m a better developer because of Github.

It’s important to note that Github has been the center of decentralized projects such as Bitcoin Core, or IPFS. Which may be problematic for many organizations realizing that their codebase is hosted online by none other than Microsoft now. I’m sure the irony is not lost on them either. The Hacker News discussion is pretty temperate so far. Very few are conflicted, and even fewer hate it. But, going forward, I believe Github will have an uphill battle regarding trust.

So, what are we to make of the new proprietor? Will Microsoft make sweeping changes to how the product operates? How will repos change? Will repos become a signal for Microsoft to source talent on LinkedIn? I’m so curious to understand Satya Nadella’s motive for acquisition. Microsoft is so huge, and we’ve all seen the negative side of acquisitions before. You know, like LinkedIn.

Ugh. Damnit. That’s the stuff of nightmares right there.

From The Verge:

Microsoft is the top contributor to the site, and has more than 1,000 employees actively pushing code to repositories on GitHub. Microsoft even hosts its own original Windows File Manager source code on GitHub. The service was last valued at $2 billion back in 2015, but it’s not clear exactly how much Microsoft has paid to acquire GitHub.

So that makes sense. I had no idea Microsoft was such a huge contributor. At any rate, Microsoft has never been great at shipping their own creations. Hell, Microsoft never even developed DOS. They bought it. From that perspective, I’m less worried than say if Google or Facebook had acquired Github.

What feels like eons ago in 2014 when Nadella joined Microsoft, John Gruber wrote:

Satya Nadella needs to find Microsoft’s new “a computer on every desk and in every home running Microsoft software”. Here’s my stab at it: Microsoft services, sending data to and from every networked device in the world. The next ubiquity isn’t running on every device, it’s talking to every device.

I thought this was noteworthy to dig up from the Daring Fireball archive. Namely because of the (very) timely news that Microsoft is now more valuable than Google. Sure, market cap fluctuates — regardless, Nadella is penning Microsoft’s new message, and it’s in permanent marker. It’s true that Microsoft in recent years has taken a backseat in services, but only because they’ve gobbled up the best talent in the world. Microsoft is and will continue to, play the long-game. This was a bold and genius move.

I’m apprehensively optimistic about this. Like I said, trust is an uphill battle. Don’t disappoint us Microsoft.

Further Reading: