git 에서 일부 파일을 다른 remote repository 에 저장하기 - aragorn/home GitHub Wiki
- http://stackoverflow.com/questions/13479763/how-to-push-a-single-file-in-a-subdirectory-to-github-not-master
- http://stackoverflow.com/questions/1384325/in-git-is-there-a-simple-way-of-introducing-an-unrelated-branch-to-a-repository
상황 1
사내 github 의 buy project 의 일부 파일을 github.com/aragorn/grails-exploration 에 동시에 commit/push 하고 싶다. 즉, 일부 파일을 서로 다른 두 원격 repository 에 push 하고 싶은 것이다.
buy repository 의 일부 파일은 feature/grails3 브랜치에서 수정하고 있다. grails-exploration repository 의 일부 파일은 master 브랜치에 반영되기를 바란다.
먼저 buy feature/grails3 브랜치를 clone 한다.
$ cd src/grails3
$ git clone https://github.daumkakao.com/KakaoBuy/buy.git grails3
$ cd grails3
$ git checkout feature/grails3
$ git status
On branch feature/grails3
Your branch is up-to-date with 'origin/feature/grails3'.
nothing to commit, working directory clean
$
orphan branch 를 생성한다.
- What is an orphan branch?
This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.
$ git checkout --orphan grails-exploration
$ git rm -rf .
$ mkdir upload
$ cp ~/src/KakaoBuy/buy/upgrade/common3 upload/
$ git add upload
$ git commit -m'initial commit'
생성한 orphan branch 의 remote repository 에 외부의 github 을 연결한다.
pull, push 과정을 거쳐 동기화한다.
$ git remote add github https://github.com/aragorn/grails-exploration.git
$ git remote show github
* remote github
Fetch URL: https://github.com/aragorn/grails-exploration.git
Push URL: https://github.com/aragorn/grails-exploration.git
HEAD branch: master
Remote branch:
master new (next fetch will store in remotes/github)
Local ref configured for 'git push':
master pushes to master (local out of date)
$ git branch --set-upstream-to=github/master grails-exploration
Branch grails-exploration set up to track remote branch master from github.
$ git pull
Already up-to-date!
Merge made by the 'recursive' strategy.
$ git push --set-upstream github grails-exploration:master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 903 bytes | 0 bytes/s, done.
Total 5 (delta 1), reused 1 (delta 0)
To https://github.com/aragorn/grails-exploration.git
ec444e0..cb80188 grails-exploration -> master
Branch grails-exploration set up to track remote branch master from github.
$
$ git remote show github
* remote github
Fetch URL: https://github.com/aragorn/grails-exploration.git
Push URL: https://github.com/aragorn/grails-exploration.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
grails-exploration merges with remote master
Local ref configured for 'git push':
master pushes to master (local out of date)
$ git push --set-upstream github grails-exploration:master
Branch grails-exploration set up to track remote branch master from github.
Everything up-to-date
$
$