Data report"State of code review 2024" is now liveRead the full report

Renaming Git repository during clone

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Guide to renaming a repository during cloning with Git

Sometimes you may need to clone a repository into a directory with a different name than the original repository, effectively renaming the repository locally. This guide will walk you through how to rename a repository during the cloning process using the git clone command, covering various scenarios and best practices.

Stop wrestling with Git commands

The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop Googling Git commands.

Learn more

The git clone command is used to create a copy of an existing repository into a new directory on your local machine. The basic syntax of the command is:

Terminal
git clone [repository URL]

By default, Git names the directory that the repo is cloned into after the name of the remote repository. However, you can specify a different directory name directly in the command to change this behavior.

To clone a repository and rename it simultaneously, you simply specify the new directory name at the end of the clone command. You can do this by running:

Terminal
git clone <REPOSITORY_URL> <NEW_DIRECTORY_NAME>

Where:

  • <REPOSITORY_URL> is the URL of the repository you want to clone.
  • <NEW_DIRECTORY_NAME> is the name of the directory into which you want the repository to be cloned.
  1. Locate the repository URL: First, you need to obtain the URL of the repository you wish to clone. This can typically be found on the repository's page on GitHub, GitLab, Bitbucket, or your self-hosted Git server.

  2. Decide on a new folder name: Choose a new name for the folder that will contain the cloned repository. This name can be anything that suits your project organization or naming conventions.

  3. Run the clone command with a new name: Open your terminal or command prompt and run the git clone command with the repository URL followed by your chosen new folder name. For example:

    Terminal
    git clone https://github.com/exampleuser/old-repo-name.git new-repo-name

    This command clones the repository located at https://github.com/exampleuser/old-repo-name.git into a local directory named new-repo-name.

  • Organizational purposes: When you are managing multiple versions of a repository or similar projects, renaming them appropriately during cloning helps keep your directories organized and understandable.
  • Avoiding naming conflicts: If you already have a directory with the same name as the repository you’re cloning, renaming it during cloning avoids conflicts and the need for manual renaming later.
The best engineers use Graphite to simplify Git

Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.

Git started for free
  • Consistent naming conventions: Stick to a consistent naming convention for your local directories to make it easier to navigate and manage your projects.
  • Check existing directories: Before cloning, check if the chosen directory name exists to avoid unintentional overwriting.
  • Understand Git behavior: Remember that renaming a directory during cloning only affects the local folder name, not the repository name on the server. The remote repository's name remains unchanged.

For further reading on cloning repositories in Git, see the official documentation.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Learn more

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2