I accidentally used git clone twice

Viewed 27

Originally, I had cloned a repo. The repo contains various R scripts that me and my colleagues have worked on.

Ideally, scripts where located in the following file path (example names used):

Fruits(The main folder) ->

  • Apple

  • Blueberry ->

    * Pie
    
    * Chocolate (The folder w/ scripts)
    
    * Milkshake
    
  • Pear

  • Strawberry

Today I was trying to add and push a new script that I had created via command line, but it kept showing as not listed as one of the changes I've made. I was also trying to receive the changes made by my peer with git add origin main, but the changes weren't showing up in the chocolates folder.

I decided to take a further look, and apparently I had created a git clone within a git clone. So now it looks like

Fruits(The main folder) ->

  • Apple

  • Blueberry

  • Fruits ->

    * Apple
    
    * Blueberry
    
    * Pear
    
    * Strawberry
    
  • Pear

  • Strawberry

Now I'm trying to figure out how to put everything into that original Blueberry -> Chocolate folder. To re-iterate, the changes that my colleague made are in that ideal folder, while the changes that I've made and want to share are in that accidentally cloned sub folder.

1 Answers

Supposing that you are dealing with only a single branch,

  1. Move the child folder out of the parent. For example, in the parent,

    mv ./Fruits ../Fruits2
    

    That particular variation will change the child folder to a sibling folder. Subsequent steps assume that choice of new location and name; adjust as necessary if you choose different ones.

  2. In both Fruits and Fruits2, commit all uncommitted changes that you want to keep.

  3. In Fruits, perform a git pull ../Fruits2 to obtain the changes and revision history from Fruits2.

  4. If any merging is needed then perform that (in Fruits/) and commit the result.

  5. Satisfy yourself that Fruits is up to date with all changes from both folders.

  6. Delete Fruits2.

Related