Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the root directory of a Git repository

Tags:

git

repository

I've got the following source structure:

/dir1
    file1
    file2
    file3

dir1 is unneeded as the repository itself can be like a folder, so I want my git repository to look like this:

file1
file2
file3

What should I do to achieve this?

like image 794
Bo A Avatar asked Aug 01 '12 16:08

Bo A


People also ask

Can you rename git root folder?

Yes, it is safe to rename the folder containing a Git repository. All paths inside the Git repository are relative.

How do I navigate to the root directory in git?

bashrc or if you use zsh in ~/. zshrc and you're all set. Whenever inside a git repo and want to cd to its root, typing gitroot will take you to its root dir.

How do I change the path on GitHub?

In your repository, browse to the file you want to move. In the upper right corner of the file view, click to open the file editor. To move the file into a subfolder, type the name of the folder you want, followed by / . Your new folder name becomes a new item in the navigation breadcrumbs.


1 Answers

DISCLAIMER: this will rewrite history and be a PITA for anyone who has already cloned your repository. You shouldn't do it on published history.

That said, you should be able to rewrite all your trees by using the filter-branch command of Git. Be sure to understand all implications before using it (please, read the manpage; have backups).

git filter-branch \
  --subdirectory-filter dir1 \
  --tag-name-filter cat \
  -- --all

NB. This command will also perist your grafts and replace refs.

like image 87
knittl Avatar answered Sep 29 '22 01:09

knittl