Is it possible to demote “master” to a sub-branch (with its entire structure) and create a new master?

There is a repository, “X”, that I forked and began doing work on to migrate it to the Jetson Nano. This fork’s “master” has several branches and is a number of commits ahead and behind the original master it was forked from. In order to participate in another project I’ve been invited to contribute to, I need a fresh, pristine, copy of the original repository. The obvious answer is to create a new fork, but that’s not possible here in GitHub without creating an organization, which is more trouble for me than it’s worth.

Therefore the solution becomes to demote the existing “master” to the status of a branch, (maintaining the structure of all its subsidiary branches), and re-clone the existing repository to a new “master” that things can branch from. (And create a new branch for the new project.)

In other words, given this structure:

main <== modified so it's != to the original "master" it was forked from
branch-a
branch-b
branch-c

I want it to become:

master <== freshly copied/forked/cloned from the original pristine master
old-master
branch-a
branch-b
branch-c
new-branch <== for project 'B' - I know how to make new branches, if I can get the "master" done correctly

This essentially becomes two main questions:

  1. How do I demote the existing “master” to the status of a branch, rename it, and create a new “master” that it is a branch of? It would be sufficient to copy the entire master/branch structure to another branch.

  2. How do I populate the new “master” branch with the original data so that the other branches have a new root-master they’re based on?

The following questions:

  • How can I make a second fork of a GitHub project?
  • Rename master-branch and create a new, empty master
  • Insert a commit before the root commit in Git?

appear to almost answer my question, but (as far as I can tell) they really don’t.

9

There are no sub branches – just a main/master branch and other branches; each of the branches can be local, remote, or both; one of the branches will be set as the upstream branch that you fetch from by default. I’ve had to something similar and this is how I would achieve it. (I will use “master”, but newer version git repos use “main”)

repopath0=~/you/repos/X.git
repopath1=~/you/repos/NEW.git

projpath0=~/you/proj/X
projpath1=~/you/proj/NEW

newbranch="identifiable-as-old-proj-branch"
oldreponame="identifiable-as-old-proj-repo"

cd $projpath1
git checkout -b "${newbranch}-master"

git remote add $oldreponame $projpath0
git fetch project-oldmaster --tags
git status # you should now see all the branches from your old repo
git merge --allow-unrelated-histories $oldreponame/master

# repeat steps beginning with cd $projpath1 for each of your "minor" branches replacing "master" with the name of the branch.

This is how I did it with self hosted git repos.
There was an issue with older servers that had older versions of git, which left me with having to omit the “–tags” (you lose tagging) “–allow-unrelated-histories”, but it still worked as far as merging. I would upgrade git if these are needed.

That being said GitHub uses git, but it is a remote hosting platform so you’ll have to use what they provide you access to. You’ll need to setup terminal access. This may help: GitHub help

New contributor

Mike Steele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật