0

I want to add my project to remote repo with another projects.

I tried to execute next:

git init
git add --all
git commit -a -m 'first commit'
git remote add origin https://myrepo.git
git push origin master

And received error that 'updates were rejected because the remote contains work that you do hint not have locally'.

I added it with 'git push -f origin master', but it was not very clever, because I removed another projects.

Is it possible to add and updated only my project without editing another ones?

obgire
  • 25
  • 6
  • It kind of is possible to have two separate branches that don't have related histories, but I think that would be cluncky to work with, at best. Anyways, check out this [answer](https://stackoverflow.com/a/4288660/6577998) – mnestorov Oct 28 '20 at 06:33
  • Do you mean, it is always better to use mono repo? 1 repo - 1 project? – obgire Oct 28 '20 at 08:10
  • Yes. It's easier to maintain the project and see/track it's development. – mnestorov Oct 28 '20 at 08:14
  • No worries :) I wrote up an answer so that it's know as a possible solution in the future. – mnestorov Oct 28 '20 at 08:28

1 Answers1

0

It is possible to have two separate, unrelated branches in one repo. This can be done, following the answer here.

git checkout --orphan newbranch
git rm -rf .
<do work>
git add your files
git commit -m 'Initial commit'

This would allow you, in newbranch, to push code that is not related to your other project, which is, let's say, in master branch.

However, I would strongly suggest you don't do thus, but rather, create two separate repositories for your two different projects. Git is made so that one project has one repo to it, instead of tracking two complete independent projects.

If one project relies on the other one, you can check out submodules.

Also note, that the --orphan option is meant as an option to create code that will later be merged to some other branch in the main project. Using it is this way, would be a missuse.

mnestorov
  • 4,116
  • 2
  • 14
  • 24