Skip to content

Instantly share code, notes, and snippets.

@opie4624
Created September 8, 2011 06:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save opie4624/1202821 to your computer and use it in GitHub Desktop.
Splitting a repository
~/Code/Work$ mkdir repoA
~/Code/Work$ cd repoA/
~/Code/Work/repoA$ git init
Initialized empty Git repository in /Users/akraut/Code/Work/repoA/.git/
(init) ~/Code/Work/repoA$ touch file1
(init file1) ~/Code/Work/repoA$ touch file2
(init file1 file2) ~/Code/Work/repoA$ git add file?
(init file1 file2) ~/Code/Work/repoA$ git commit -m 'add test files'
[master (root-commit) 6be573c] add test files
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file1
create mode 100644 file2
(M=6be57) ~/Code/Work/repoA$ git remote add origin git@github.com:opie4624/repoA.git
(M=6be57) ~/Code/Work/repoA$ git push -u origin master
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 216 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:opie4624/repoA.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
(M=6be57) ~/Code/Work/repoA$ git checkout -b files-to-keep
Switched to a new branch 'files-to-keep'
(files-to-keep=6be57) ~/Code/Work/repoA$ git rm file2
rm 'file2'
(files-to-keep=6be57) ~/Code/Work/repoA$ git commit -m 'delete the files that are moving'
[files-to-keep 9229510] delete the files that are moving
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 file2
(files-to-keep=92295) ~/Code/Work/repoA$ git checkout master
Switched to branch 'master'
(M=6be57) ~/Code/Work/repoA$ git checkout -b 'files-to-move'
Switched to a new branch 'files-to-move'
(files-to-move=6be57) ~/Code/Work/repoA$ ls
file1 file2
(files-to-move=6be57) ~/Code/Work/repoA$ git rm file1
rm 'file1'
(files-to-move=6be57) ~/Code/Work/repoA$ git commit -m 'delete the files that are NOT moving'
[files-to-move 14ea73b] delete the files that are NOT moving
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 file1
(files-to-move=14ea7) ~/Code/Work/repoA$ git push git@github.com:opie4624/repoB.git files-to-move:master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 433 bytes, done.
Total 5 (delta 0), reused 0 (delta 0)
To git@github.com:opie4624/repoB.git
* [new branch] files-to-move -> master
(files-to-move=14ea7) ~/Code/Work/repoA$ git checkout master
Switched to branch 'master'
(M=6be57) ~/Code/Work/repoA$ git merge files-to-keep
Updating 6be573c..9229510
Fast-forward
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 file2
(M=92295) ~/Code/Work/repoA$ ls
file1
(M=92295) ~/Code/Work/repoA$ git push
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (1/1), done.
Writing objects: 100% (2/2), 242 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
To git@github.com:opie4624/repoA.git
6be573c..9229510 master -> master
(M=92295) ~/Code/Work/repoA$ git branch -d files-to-keep
Deleted branch files-to-keep (was 9229510).
(M=92295) ~/Code/Work/repoA$ git branch -d files-to-move
error: The branch 'files-to-move' is not fully merged.
If you are sure you want to delete it, run 'git branch -D files-to-move'.
(M=92295) ~/Code/Work/repoA$ git branch -D files-to-move
Deleted branch files-to-move (was 14ea73b).
(M=92295) ~/Code/Work/repoA$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment