I have a branch (let's call it branch1) in a repository (repo1) and I want to push some of its files into another branch (branch2) of a repository (repo2). How can I do this in GitHub? I don't want to upload files manually because I need to upload the commits also. Thank you
Asked
Active
Viewed 52 times
1 Answers
0
Add that second repo as a remote, then you can push to it. Push-syntax allows to specify a branch name to use.
$ git add remote repo2 https://github.com/foo/repo2
$ git push repo2 branch1:branch2

Oliver Baumann
- 2,209
- 1
- 10
- 26
-
I'm sorry but i'm quite new on GitHub, do I have to use this conde in my git console? Moreover, does this push everything from branch 1 to branch 2? Because I don't want to push all files – Federico Taschin Nov 10 '17 at 21:40
-
Yes, these are commands you'd type in the console. Yes, this pushes all the commits on branch1 to branch2 of the other repository. Also, do you mean "files" or "commits"? This will be an important detail – Oliver Baumann Nov 10 '17 at 21:42
-
Ops, I badly explained myself, sorry. I would like to push only some files and their related history of modifies, but now I realize that a commit includes many files and maybe it's not possible to keep only commits of the file that I want to push – Federico Taschin Nov 10 '17 at 21:49
-
What you could do is, from the parent of `branch1`, say `master`, create a new branch, say `tmp`. `tmp` will not contain the changes in `branch1`. Then, you could cherry-pick the commits you want from `branch1` into `tmp` and push that to the other remote. Re: cherry-picking perhaps see [this question](https://stackoverflow.com/questions/9000918/how-to-cherry-pick-interactively). But, again, this will only transfer commits. – Oliver Baumann Nov 10 '17 at 22:04