How to rename a remote repo in Git

Posted in Development and Git

When I made the move to CLI-only Git last summer I realised that I had been in the habit of naming my repositories after the project. So, for example, Project X’s repo would be named project-x.

This was fine when I was clicking around a GUI but it quickly got annoying when working on the command line, where my fingers always went to type origin (the conventional remote name). So instead of git push remote origin feature/feature-name I would have to type git push remote project-x feature/feature-name.

I did have some teething problems with this one – the first time I tried it, I must’ve done something wrong as it caused all sorts of problems that I had to go back to my GUI for and fix, then re-track all the remote branches. So having tried, I thought it was complicated, and resolved to put up with all the unique and often lengthy remote names. But the other day, I finally got fed up, took a deep breath, and tried again.

It turns out it’s very simple to rename a remote… In fact that’s the command: rename! And the good news is, once renamed, all the tracking you set up stays intact: no need to do any git branch -u remote-branch-name as master will still be tracking master, develop will still be hooked up to develop, etc.

Before you do this, be sure you tell anyone else who might be working in the same repo – they’ll need to re-attach to the newly named remote.

How it’s done

Start with a quick git remote to see the name of your remote repositories. Copy and paste the name of the one you want to change (maybe a typo was my problem that first time?) and run this command, pasting your remote name over the top of project-x:

git remote rename project-x origin

And that’s it!

Pushing, pulling and fetching will now work exactly as they did before, but when you need to type the remote name it’ll be the consistent and standard origin.

Note: you can call it whatever you want, of course. That last value of the command in the example is the name you want to rename the repo to. Just swap origin for project-y or whatever you like!

Get them delivered!

If you enjoyed this and want all the latest articles delivered to your inbox every month, pop your email in the form below.

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that's not enough, have a look at the full list.

  1. Text snippets on Apple devices

    I’ve been using Apple’s built-in Text Replacement instead of TextExpander for a while now. It’s pretty basic, but it’s free and it does the job.

  2. The right way to use break tags in HTML

    Break tags are often misused. I’ll demo some markup patterns to avoid them, and reveal the one and only legitimate use case I can think of.