Spoiler alert: this is not as daunting as it sounds 🙌
So today, I decided to change the root folder of my GitHub repository from the parent folder I had initially initialised the repository in, to a child folder in the same directory.
I almost didn't bother as I had flashbacks of past nightmare experiences changing things on git but I decided to give it a go and luckily it was much easier than I thought wooo!
I thought I would record this for my future benefit and yours.
Essentially what you need to do is move the .git folder to the folder you want to be the root folder.
These are the steps I took in the command line (remember I am moving my .git one folder inwards - you will need to adjust the commands to your needs).
In the below example, $ represents a command line prompt which may look slightly different to yours.
Start by moving your .git file to the folder that you want to go to.
- $ mv .git
Then navigate to that folder.
- $ cd
Then add all the changes to the staging area. Git will detect these files as renamed versions of old files that were 'lost' and so no history will be lost.
- $ git add .
Commit all the changes with the -a command. The -a command stands for all. It tells the commit command to automatically stage files that have been modified and deleted whilst new files that you have not told Git about are not affected.
- $ git commit -a
Finally, push the changes to your repo. You might see a prompt that asks for a merge message and in this case you will need to follow the additional steps below.
- $ git push
You may receive the following git merge error message:
Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch
To solve this:
- Press “i”
- Write your merge message
- Press the “esc” key.
- Type “:wq”
- Then press enter
You will then to git push again and you're done!