

You can delete both the cloned repositories. Step 6: Finally, push the changes git push Step 5: Remove the remote connection to repository A. git pull repo-A master -allow-unrelated-histories # This merges master from repository A into repository B Step 4: Pull files and history from this branch (containing only the directory you want to move) into repository B. git remote add repo-A # (repo-A can be anything - it's just a random name) # eg. Step 3: Create a remote connection to repository A as a branch in repository B. cd newproject # Folder Path is ~/cloneB/newproject Step 1: Make a copy of repository B if you don’t have one already. git commit Merge the files into the new repository B.

mkdir #eg mkdir NEW_FOLDER mv * #eg mv * NEW_FOLDERĪlternatively, you can drag all the files and directory to the NEW_FOLDER using GUI. Step 6: Move all the files and directories to a NEW_FOLDER which you want to push to repository B. git reset -hard git gc -aggressive git prune git clean -fd git filter-branch -subdirectory-filter subfolder1/subfolder2/FOLDER_TO_KEEP -all git filter-branch -subdirectory-filter -all # eg. The result is the contents of FOLDER_TO_KEEP spewed out into the base of repository A. Step 4: Go through your history and files, removing anything that is not in FOLDER_TO_KEEP. Fork a repository on GitHub Clone it onto your computer Make a branch and move to it: git checkout -b fixingBranch Make changes to the files Commit the. by pushing), delete the link to the original repository. Step 3: To avoid accidentally making any remote changes (eg. cd myproject # Folder Path is ~/cloneA/myproject git clone -branch master -origin origin -progress \ # -v # (assuming myprojects is the repository you want to copy from) Step 1: Make a copy of repository A as the following steps make major changes to this copy which you should not push! mkdir cloneA cd cloneA git clone -branch -origin origin -progress \ -v # eg. Moving the files with history to a different repository requires the following steps: Getting files ready to move from Repository A. When we simply try to move files from one repository to another we lose the entire history of that particular file, and we can’t trace it back anymore.
Today at we reached a point when we start to split our large repository into several small sub-projects. Make changes to your package master branch and commit them to your local repository git addIn the multi-repository project structure, its only a matter of time when you’ll want to refactor some files from one project to another. Move files from one repository to another, preserving git history
