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!

Subscribe

If you enjoyed reading this and want a monthly roundup of my articles delivered to your inbox, just enter your email 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. Mac event 2021

    Apple had their final event of the year last night and it was especially exciting as I’m in the market for a new Mac. Here are my thoughts.

  2. Face ID on the Mac won’t happen

    With an October Mac event looming, I got to thinking about Face ID on the Mac; I don’t think it’ll be added now, and might not ever be.