banner
keney

keney

remain optimistic
twitter

Managing multiple projects with a single GitHub repository

Prerequisites#

You need to be relatively familiar with git commands; you can refer to [Common Git Commands](Common Git Commands.md).

Background#

There are many practice projects, but storing them on a company computer is not a suitable choice (inconvenient to view everywhere).
Additionally, with recent frequent use of Git, the idea of uploading projects to a GitHub repository for management emerged.
Initially, the idea was to create folders in a single repository to distinguish projects, but later it felt inappropriate (every time I looked from elsewhere, the entire content of the branch was cloned down).
Finally, I discovered that orphan branches (placing N completely different projects as N branches in the same repository, with no impact between branches) could completely solve this problem.

Specific Steps#

Operate the following commands under a git repository.

Create an orphan branch

git checkout --orphan [branch name]

This creates an orphan type branch.
Why use an orphan type branch?
Reason: To place N completely different projects as N branches in the same repository, with no impact between branches.
The core purpose of git checkout --orphan is to create a branch in a state similar to git init on a non-new repository.

Check branch status

git branch

This will list all local branches.

Commit code

git add ./
git commit -m "commit branch"
git push origin [branch name]

Why push?
Because after creating the branch locally, it still needs to be submitted to the remote repository to truly create a new branch.

Note:

When creating other orphan branches, it is recommended to switch back to the main branch before creating a new orphan branch.

Extension#

Switch branches:

git checkout [branch name]

Create a new branch from the current branch:

git checkout -b [new branch name]

At this point, the new branch will have all the files from the current branch.

Attachments#

References: https://blog.csdn.net/Wrysmile0308/article/details/119619702
Reference 2: https://www.cnblogs.com/asdfq/p/13277559.html
Reference 3: What is git checkout --orphan used for

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.