mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-23 11:15:34 +08:00
2.3 KiB
2.3 KiB
- create an orphan branch
git checkout --orphan 'third-party/my-branch'
- make sure no files are staged yet
git rm -r -f --cached .
- copy some new files (or add ones that already exist)
cp ~/myfile.txt ./
- stage the required files
you can also stage all files in the current directorygit add myfile.txt
git add .
- commit the files
git commit -m 'my commit msg'
- add the branch as submodule
git by default disallow local repos, this optiongit -c protocol.file.allow=always submodule add -f -b 'third-party/my-branch' file://"$(pwd)" 'my-relative-dir/without/dot/at/beginning'
protocol.file.allow=always
forces git to allow it
this will:- look for a local repo in the directory shown by
pwd
(current folder),
notice how we don't simply use./
because if we did that git will try to use theorigin
of the repo,
and since the origin (github/gitlab/etc...) doesn't have this branch yet it will fail, using the file protocol (file://absolute_path
) forces git to use the local repo files
you can of course push the branch to origin before doing this step - look for a branch named
third-party/my-branch
- create a submodule pointing at this branch inside a new folder
my-relative-dir/without/dot/at/beginning
notice that the new folder does not start with./
as usual
- look for a local repo in the directory shown by
- fix the submodule path
after the last command, the file.gitmodules
will point at the absolute path of the repo on disk, fix it to be relative
this time git won't try to grab the data from origin, it will just editgit -c protocol.file.allow=always submodule add -f -b 'third-party/my-branch' ./ 'my-relative-dir/without/dot/at/beginning'
.gitmodules
- new git management objects/files will be staged, you can view them
possible outputgit status
On branch third-party/my-branch Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: .gitmodules new file: third-party/my-branch
- commit these 2 files
git commit -m 'add branch third-party/my-branch as submodule'