Tag Archives: git

Git: How to remove submodule

Quick tip on how to remove Git submodule.

  1. Remove the relevant line from the .gitmodules file
  2. Delete the relevant section from .git/config (if any)
  3. Run
    git rm --cached path_to_submodule

    (without trailing slash)

  4. Commit and delete the now untracked submodule files.

Moving Files from one Git Repository to Another, Preserving History

Once upon a time all my Android apps and VMSoft related stuff were part of one big BitBucket git repository along with an issue tracker. This was a good idea when being an Android dev was just a hobby for the weekends and not my primary job.

Enough rambling 🙂 , this blog post is about moving files from one git repository to another and preserving your history.

Our goal is to move a single directory from one big Git repository to it’s own repository, we would like to preserve the commits history for that specific directory also.

In this example our big repo will  be called A and our new repo that will host it’s own subset of files will be called B

First filter the files from the big repo (A) by leaving only the ones you need:

git clone < repo A url >
cd < repo A directory >

Remove the “origin”

git remote rm origin

and filter A by < directory_to_move >. This action will go trough all the history and files and remove anything that’s not in < directory_to_move >.
More info on the inner workings of git filter-branch here.

git filter-branch --subdirectory-filter <directory_to_move> -- --all

filter-branch will leave you with the contents of < directory_to_move > in the root of repository A. Commit the changes and we can continue with the next step.

git add .
git commit

Moving to the new repository

Link repo A with repo B. The command below will make repository A branch of repository B.

git remote add repo-A-branch <git repository A directory>

Pull from the branch allowing unrelated histories

git pull repo-A-branch master --allow-unrelated-histories

and finally remove repo-A-branch

git remote rm repo-A-branch

That’s it, you now have your files in a new repository while preserving commits history.

Git checkouts fail on Windows with “Filename too long error: unable to create file”


According to the msysgit wiki on GitHub and the related fix this error, Filename too long, comes from a Windows API limitation of file paths having 260 characters or fewer.


To resolve this issue, run the following command from GitBash or the Git CMD prompt (as administrator):

git config --system core.longpaths true

This will allow file paths of 4096 characters.

TortoiseGIT Disconnected: No supported authentication methods available ( server sent: publickey )

After migrating to SSH authentication for my Bitbucket repo ( one of the reasons for doing that was to be able to mirror my repo on my home server, article on that topic coming soon ), the TortoiseGIT windows client stopped working. It was unable to do pulls and pushes and all other functionallity related to connecting to the remote GIT. Android Studio and other IDE’s and tools I use on a daily basis, including git command line client were working properly.


TortoiseGIT uses Pageant (part of the PuTTY toolset) to manage it’s authentication keys. Because I have already generated the public / private key pair using ssh-keygen all I needed to do was make Pageant aware of them.

For this Puttygen (part of the PuTTY toolset) should be used.



Load the key in Puttygen (you will be prompted for password during the loading process), leave the default settings. If the import was successful you will get a message telling you so.


Then click ‘Save private key’ button and save your private key in putty default ppk format. Fire up Pageant and load your newly created key.


Now pulls, pushes and all other functionallity related to connecting to the remote GIT should work as expected.


NOTE: Pageant should be started prior to using TortoiseGIT, else you will get the same error message again.