Moving files from a Git repository to another keeping history

Yesterday I had to move a few files from a Git repository A to repository B while working on a client’s project. Today I had to do it again on another project. Again I had to think about the sequence of commands I had used. For this reason I’m posting this here.

Prepare repository A (the source)

git clone --no-hardlinks /path/to/sourcerepository repositoryA
cd repositoryA
# remove remote origin just so we can't break anything in the source repository
git remote rm origin
# filter for desired files
git filter-branch --subdirectory-filter directory HEAD
# move around files, etc.
# then commit
git add .
git commit -m"isolated files"

In line #1 we clone the source repository so we can’t break the original one, we also remove the remote in line #4 so no links back to the source repository exist. Next using the filter-branch command we filter out everything but the directory we want to keep. Read more

Pull files to new repository

git clone repositoryB_URL repositoryB
cd repositoryB
git remote add repositoryAbranch /path/to/repositoryA
git pull repositoryAbranch master
git remote rm repositoryAbranch

Git Workshop mit Matthew McCullough (Github Trainer)

Git Workshop mit Matthew McCullough (Github Trainer)

Subversion, das wohl immer noch am weitesten verbreitete SCM im Java-Bereich, muss sich in letzter Zeit einige Kritik gefallen lassen.
Tatsächlich häufen sich die Anzeichen, dass die Konkurrenten aus dem Lager der verteilten Systeme immer mehr an Popularität gewinnen. So wechseln immer mehr Projekte auf das verteilte Versionsmanagementsystem (DVCS) Git.Ist das nur ein temporärer Hype oder eine technologische (R)Evolution?

Am 4.Mai 2011 gibt es erstmals in Österreich einen Git Workshop mit Matthew McCullough (offizieller GitHub Trainer) und somit eine einmalige Gelegenheit zu erfahren was denn hinter dem Erfolg von Git steckt.

Anmeldung per EMail (mit Name und Adresse des anzumeldenden Teilnehmers) an office@martinahrer.at.
 Zum Workshop in Englisch werden maximal 20 Teilnehmer zugelassen, ein eigener Laptop ist mitzunehmen.

Anmeldung von Gruppen ab 3 Personen zu ermäßigtem Preis auf Anfrage. Im Preis enthalten sind Getränke sowie ein Brötchenbuffet zu Mittag! Ermäßigtes Parken in der Hoteltiefgarage ist möglich.

Zur Anmeldung

Read more

green red blue grey