Let's say where I have a git branch like this sampath-test. I created this branch from the master repo. I have created another fresh repository (master) like ionic3-refactored. This new master repository only has a readme file. So could you tell me how can I merge sampath-test code to fresh master repo ionic3-refactored?
Asked
Active
Viewed 52 times
0
Sampath
- 63,341
- 64
- 307
- 441
-
https://stackoverflow.com/questions/1778088/how-to-clone-a-single-branch-in-git maybe, although I don't really understand what you're trying to do – Mat Jun 10 '18 at 08:05
-
The link https://stackoverflow.com/questions/21353656/merge-git-repo-into-branch-of-another-repo/21353836 should be helpful in your case. – Samit Jun 10 '18 at 08:07
-
I have added more content. Please see that too @Mat – Sampath Jun 10 '18 at 08:28
1 Answers
0
You can use git push to do this.
git push <path to repository> <local branch name>:<remote branch name>
Here's an example.
First, here's the source repository. The master branch has a few files and the branch1 branch has an additional file:
$ git branch
branch1
* master
$ ls
file1.txt file2.txt README
$ git log | grep -v Author
commit 56cd34350e846b92762d16af1c777ff4075fff3e
Date: Sun Jun 10 01:02:23 2018 -0700
Add file1.txt and file2.txt
commit c5d453a847d3b61b75f8a27de3b3cdc163421398
Date: Sun Jun 10 01:01:55 2018 -0700
Add README
$ git checkout branch1
Switched to branch 'branch1'
$ ls
file1.txt file2.txt file3.txt README
$ git log | grep -v Author
commit bbdbd16488f835ee9bd0903274e45d18b0e621a1
Date: Sun Jun 10 01:02:53 2018 -0700
Add file3.txt
commit 56cd34350e846b92762d16af1c777ff4075fff3e
Date: Sun Jun 10 01:02:23 2018 -0700
Add file1.txt and file2.txt
commit c5d453a847d3b61b75f8a27de3b3cdc163421398
Date: Sun Jun 10 01:01:55 2018 -0700
Add README
Here's creating a new repository and pushing newbranch into it along with it's history:
$ mkdir ../newrepo
$ cd ../newrepo/
$ git init
Initialized empty Git repository in /home/chuckx/code/stackoverflow/gitpush/newrepo/.git/
$ cd ../repo1/
$ git push ../newrepo/ branch1:newbranch1
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 596 bytes | 596.00 KiB/s, done.
Total 7 (delta 1), reused 0 (delta 0)
To ../newrepo/
* [new branch] branch1 -> newbranch1
$ cd ../newrepo/
$ git branch
newbranch1
$ ls
$ git checkout newbranch1
Switched to branch 'newbranch1'
$ ls
file1.txt file2.txt file3.txt README
$ git log | grep -v Author
commit bbdbd16488f835ee9bd0903274e45d18b0e621a1
Date: Sun Jun 10 01:02:53 2018 -0700
Add file3.txt
commit 56cd34350e846b92762d16af1c777ff4075fff3e
Date: Sun Jun 10 01:02:23 2018 -0700
Add file1.txt and file2.txt
commit c5d453a847d3b61b75f8a27de3b3cdc163421398
Date: Sun Jun 10 01:01:55 2018 -0700
Add README
chuckx
- 6,484
- 1
- 22
- 23