Skip to main content

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!

Accessibility in your inbox

I send an accessibility-centric newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

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. Avatars and alt text

    I really enjoyed Nicolas Steenhout’s recent article on Alt text for avatars or user photos. But there is a context where I would break his rule…

  2. Upgrading from iPhone 13 mini to 16 Pro

    I get a new phone every 3-ish years, give mine to my wife, and now she gives hers to our daughter. I got a 16 Pro this year! Here’s the skinny.