2

I've just finished development on my template engine, Squirrelly. I have the current version stored in a GitHub repo at https://github.com/squirrellyjs/squirrelly and the new version at https://github.com/squirrellyjs/squirrelly-next.

My question has to do with finally publishing on NPM. Initially I had planned to publish at squirrelly-next and then merge later, but I think I've decided to just publish at squirrelly@8.0.0.

The problem, however, is that all new development is in the squirrelly-next repo, and I need to somehow get the code and history to the squirrelly repo (with a branch for v7).

I've actually just considered renaming https://github.com/squirrellyjs/squirrelly to https://github.com/squirrellyjs/squirrelly-v7 and https://github.com/squirrellyjs/squirrelly-next to https://github.com/squirrellyjs/squirrelly. Would there be any potential drawbacks to this? If so, how can I get my Git repo from squirrelly-next to the master branch of squirrelly?

kowsky
  • 12,647
  • 2
  • 28
  • 41
Ben Gubler
  • 1,393
  • 3
  • 18
  • 32
  • Creating separate git repos for the same source code kind of defeats the purpose of branches. That being said, this seems to be what you want: https://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories – user2263572 Jan 29 '20 at 01:36
  • @user2263572 well, I actually completely rewrote the library (new infrastructure, Typescript instead of JavaScript, new testing, etc.) so it wasn't the same source code. But I see your point :) – Ben Gubler Jan 29 '20 at 02:23
  • Well as per my understanding, there are two repositories for the project and you want to move one branch to another repository right? – Prateik Darji Jan 29 '20 at 04:02
  • @PrateikDarji yes basically. – Ben Gubler Jan 29 '20 at 04:03
  • I have updated my answer for new branch and existing branch as well – Prateik Darji Jan 29 '20 at 04:34

2 Answers2

4

There may be multiple options to do that however, I am describing the one which I uses the most is that you can add two repositories in your project.

suppose there is one set as your origin,

https://github.com/squirrellyjs/squirrelly

you can check that by git remote -v which gives you list or remote repositories.

you need to create one fresh repository to which you needs to move your code which is

https://github.com/squirrellyjs/squirrelly-next

then, back to your project follow the command as below.

git remote add new-origin https://github.com/squirrellyjs/squirrelly-next

git fetch new-origin

that's it,

Now if you want to move any branch from origin to new-origin just do it as below. suppose I'm taking an examble that we want to move master branch of old origin to new-origin

we just need to check out to master branch of our old origin

if no branch exists on new repository

git push new-origin master

And if exists then first you need to get the new repository branch in local

git checkout new-origin/master

creating branch at local.

git checkout new-master

we need to rebase if new-master with master before merging master to new-master

git checkout master //which is from old repository.

git rebase new-master

resolve conflicts if any

git checkout new-master
git merge master
git push new-origin/master

this will have latest code and also the code from old repository.

then you need to set tracking for the branch in local,

git branch --set-upstream-to=new-origin/master

or you can remove the old origin and rename new-origin to origin

git remote rm origin
git remote rename new-origin origin

if you follow the second step you don't need to change the tracking information of branch.

Prateik Darji
  • 2,297
  • 1
  • 13
  • 29
0

I realized that trying to merge my new repository with my old one wasn't actually necessary, since they have unrelated histories and the new one started from an empty repository.

So, I ended up just creating a new blank branch using https://stackoverflow.com/a/34100189/7983596.

Then, I added the remote path to my new repository and merged my new repo with my new blank branch (careful: I needed to git add . and git commit first).

After, I followed this guide: https://multiplestates.wordpress.com/2015/02/05/rename-a-local-and-remote-branch-in-git/ to rename my old master branch to v7 and then rename my new empty branch to master. (I had to change the default branch on GitHub)

Ben Gubler
  • 1,393
  • 3
  • 18
  • 32