git-subtree | experimental alternative to the git-submodule command
kandi X-RAY | git-subtree Summary
kandi X-RAY | git-subtree Summary
Please read git-subtree.txt for documentation. Please don't contact me using github mail; it's slow, ugly, and worst of all, redundant. Email me instead at apenwarr@gmail.com and I'll be happy to help.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of git-subtree
git-subtree Key Features
git-subtree Examples and Code Snippets
Community Discussions
Trending Discussions on git-subtree
QUESTION
I had a repository with this history:
...ANSWER
Answered 2020-Jun-19 at 05:59You can create a new repo, add both repositories as remotes, and rebase the second onto the first:
Here's repo 1:
QUESTION
I'm trying to understand the difference between git subtree split & git filter-branch for a particular use case. This question is similar to Difference between git filter branch and git subtree?, but not exactly the same.
Given a repo with /sub/folder, execute these commands:
...ANSWER
Answered 2020-Apr-11 at 01:03The short part is just as you put it in your comment summary:
... in my use case above there is no difference.
However, the general advice would be to use git subtree
: it's more direct, less error-prone, and should continue working even if-and-when git filter-branch
stops working someday.
Essentially, you've independently re-discovered how the git subtree
command came into existence: various users wanted to take their existing repository, extract some part of it—typically a library—and export that as a new Git repository. The git filter-branch
command could do that, so that is what they did.
This was popular enough, and useful enough, that git filter-branch
grew a filter named --subdirectory-filter
dedicated to the job. See commit 685ef546b62d063c72b401cd38b83a879301aac4
by Johannes Schindelin, in 2007, first released in Git version 1.5.3.
Subtree splitting itself was not really enough (and git filter-branch
is a kind of dangerously-overpowered tool), so in April 2009, Avery Pennarun introduced the git subtree
command, starting with commit 0ca71b3737cbb26fbf037aa15b3f58735785e6e3
, as an experimental script for the 1.7.11 release candidate. This implemented split and, almost immediately, --rejoin
and add
as well. The first actual installed version—rather than add-on distributed with Git—is from commit 0d31de303f9e8e28cc1649dbf41c1cc635bae2d8
by Ben Walton. All this was released in Git 1.7.11.
Recently, git filter-branch
itself has been formally deprecated: it's difficult to use correctly, slow, and just generally not very nice. A new git filter-repo
command is faster and more useful, though it does require that you know enough Python to use it, and it's still not distributed with Git itself. But git subtree
, which has a specific purpose rather than a general one, will stick around, and should have the same usage in the future even if git filter-repo
actually replaces git filter-branch
entirely.
QUESTION
I have a repo that contains a subtree that has some build and config files.
...ANSWER
Answered 2020-Feb-21 at 20:29It's not going to work that way. The Git documentation on gitignore says (emphasis mine)
Each line in a gitignore file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):
- Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.
QUESTION
I have a common library that I want to share between a few solutions, that stored in different github repositories. We put the shared library in separate GitHub repository and created nuget package, that can be installed in each required projects/solution. The disadvantage is that changing code in a library involves a few steps ( change code, push to library repository, creating nuget package, installing package) which is annoying.
I wanted to use git subtree
to create sub directory with library project and use it as local project in my solution with easy code changing/testing/debugging.
Developers of "Main" solutions will have a choice- include library as a binary nuget package or as a source project in subdirectory.
PROBLEM: When I tried git subtree
, I found one issue: csproj files have relative references to packages folder, that are located on different levels, when included in standalone library solution and when included in a main solution.
When in MyLib.sln the path is "..\Packages" , but in Main.sln the path should be "..\..\Packages" .
The structure of Main GitHub Repository ( and OtherUserOfMyLib GitHub Repository(is)) :
ANSWER
Answered 2019-May-11 at 21:48I was able to use git subtree to share the common repository (e.g. source code library) as subfolder of different client solutions(repositories) and allow to push the changes back to the shared repository.
We are using similar approach for c# libraries, folder of Powershell psm modules, consider to use for collection of React jsx components. For c# library one of the client repositories builds NuGet package, that can be used by any solution which prefer to refer NuGet package instead of source code.
The same approach we are using if we need to include source code of some open source github library ( e.g. if we want the changes before a new release is available).
In each application repository we need to customise two batch files (for each common repository): subtreePull and subtreePush.
Examples of batch files (based on option 4 of Add subdirectory of remote repo with git-subtree answer) :
MyCommonLib-SubtreePull.cmd
QUESTION
I've set up a Heroku app, lucy-staging
:
ANSWER
Answered 2019-Apr-01 at 16:58I managed to push the subtree to the master branch of the remote using the following command:
QUESTION
I want to merge 2 Rails application "we can call source" into another Rails application "we can call target" distributed into subfolders without losing git history.
I want to merge only the main folders of rails.
e.g.
merge source/subfolder >> target/subfolder/source
merge source/subfolder/file.rb >> target/subfolder/source/file.rb
...ANSWER
Answered 2018-Aug-02 at 13:46I would recommend following the merge-and-move strategy instead of subtree: to me, it keeps the history clearer (and unchanged).
- Move the directories around in the source repository to produce the shape you want (deleting any files you don't want to bring across)
- Commit that (on a temporary branch if you like)
- Add the source repository as a remote in the target checkout
- Merge the relevant branch from source into target, and commit
- Apply any additional post-merge cleanup, connect the new parts together, etc.
There isn't really anything Rails-specific about that strategy, but as we're tagged for it, here's an example where I recently did the above: https://github.com/rails/rails/pull/32097
QUESTION
I’m looking for a way to have a file or (better yet) a directory in a project repo that is part of the repo (tracked), but is left unchanged by switching branches.
Also, know that I am not adverse to considering something other than Git. Its just what I'm use to.
Use case:I have a personal project which I want to apply the magic of git to. There is one catch so far.
I have a file that is not part of the actual code. It is not meant for production. Its sole purpose for existence is so that I have a place to write down ideas when they come to me, or to brain storm when I'm stuck. I usually am editing this in parallel with whatever else I'm doing, and I keep it open at times. It doesn’t matter what I’m doing, its the same file whose contents are in no way dependent on what branch I’m on.
I do not want this file altered when I switch branches. To me, its kind of this floating file that is part of the project and could use versioning. However, its not really connected in a coding way to the rest of the files so when I checkout some files, this floating file should not change, but when I commit, I want the planning file to be committed as well, but not so much to a branch but to the repo. This of course doesn’t make sense because Git doesn’t work that way, but that doesn’t mean that I can’t do something that provides a similar result.
In short. . .I have some files that are part of a project but exist outside the normal structure. I want these files tracked, but left unchanged when I switch branches, or always exist in the same form on all branches.
Things to note- I am the only one committing (or even looking at it).
- I have two machines I will be using when working on this.
- When I push the repo to remote, I want everything pushed.
- The file in question is not shared with other projects (the normal use of subtrees and submodules).
- Unless there are unavoidable technical limitations, I don’t see having more than one remote (the one for the project).
- These files don’t need any kind of multi-branch scheme for themselves (all commits for that file exist on the same branch or simultaneously to all branches).
The first thing I search for was “branch specific exclusion” which lead to worktrees. This can sort of be done with per worktree exclusion. What I figure I can do is have a work tree ../planning/
, set it to exclude everything except the contents of ../planning/planning/
(which exists as ./planning/
in the main tree). In the main tree, I then merge in the planning branch.
The problem here is that the directory structure is weird, and files are unnecessarily redundant. Also, I can foresee a merge going wrong and messing up the rest of the files in the project.
Also a little voice in my head is telling me that I’m overlooking some major flaw.
SubmoduleThinking of overlooking things and major flaws. . .submodules (which seem to be the single most maligned feature of git).
The next thing I came across was a submodule. This was in my search for “subproject”, which are like independent repos inside another repo. Then I started reading about them. The main problems as far as I’m concerned are that they seem to need their own remote (don’t want this), and unless you are constantly vigilant, you can easily mess things up, sometimes silently. Errors are bad; silent errors are much worse.
Even if I was willing to hope I don’t mess up to terribly, submodules seem to be of use when you have a separate upstream, which is exactly the sort of thing I don’t want. Of course, if this is what needs to be done. . .so be it.
SubtreeUnless I’m missing something, I don’t see any advantage of using subtrees, in my case, to symlinking a repo to subdiretory.
It seems to me as if a subtree is less of a part of the “super-tree” than a submodule is.
However, since this is just a bash script, it seems as if I can make something like this work that doesn’t require a separate remote.
Use an orphaned branchWhile searching for “one repo several projects” I found a Stack Overflow question on that very subject (not mine, but what I searched). The best/first answer was about orphaned branches. This looked really promising since it most closely matches what I had in my head---a separate branch from the main trunk. The problem is it I can’t be working on both the planning documents (which are always open) and whatever file from the actual project needs to be worked on.
Gitslave/MetaAt first I thought either Gitslave (which is no more) or Meta, would be able to do what I want, after learning of them, but it doesn’t appear so. They perform the same action, it seems, on each repo in the super/meta-repo. If I had two repos, then the one for planning would have an extremely simple branch structure; what branch I’m on in the planning repo shouldn’t change based on what I’m on in the main repo.
Just have a separate repoWhile this would accomplish part of what I want, it runs contrary to the stated requirement that the files in question are part of the project repo. This is the fall back in case what I want is impossible since it accomplishes everything else.
To keep everything tidy, I’d symlink files into place within the directory for the main project.
Final thoughts:So far none of the things I’ve looked at or considered seem to do what I want them to. At this point I doubt there is a solution that fits what I am looking for, however, I’m hoping that someone with more experience knows of something I am overlooking that might satisfy my needs. If not, then I would like to know what my best option is among imperfect solutions.
Continued efforts Commit to all branches.Someone actually asked this here and the answer was that Git doesn't have this feature and the reasons were given. It was a shot in the dark, and I didn't think that it would be possible, but. . . one can hope right?
Other things I’ve read:https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree
https://spin.atomicobject.com/2016/06/26/parallelize-development-git-worktrees/
What would I use git-worktree for?
https://git-scm.com/book/en/v2/Git-Tools-Submodules
Difference between subprojects and submodules in Git?
https://www.quora.com/How-do-I-handle-sub-projects-using-Git
https://gist.github.com/gitaarik/8735255
https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407
https://medium.com/@porteneuve/mastering-git-subtrees-943d29a798ec
https://makingsoftware.wordpress.com/2013/02/16/using-git-subtrees-for-repository-separation/
What's the best practice for putting multiple projects in a git repository?
...ANSWER
Answered 2018-Jul-30 at 00:23I have a fairly satisfactory solution. With all the things I've considered before in front of me I considered combinations of them. In particular the worktree and the orphaned branch.
The conceptThe concept is to have a worktree that is on an orphaned branch.
The orphan has nothing in common with anything else in the project, which is desired since the planning documents are not part of the code. This method produces an empty directory so there is no mess. It just looks like another directory, but you do have to make a separate set of commits, though I think there is a way to commit all branches at the same time.
How to do it. Step 1: Make a repoQUESTION
I have a big private repository which is maintained on a local network. I'd like to automatically push a subtree of that repository outside of that network. I need it to be simple:
*Task* someone pushes to local remote repository --> a subtree is automatically pushed to some other repository
I am not sure if this could be achieved with a server side hook because AFAIK there is no such thing as pushing subtrees from bare remotes. I came up with two ideas:
- I could clone the remote on the server and automatically split the subtree in the cloned remote. This doesn't really help because I don't know how to auto-pull the subtree (others also have this problem).
- Another idea is to write a custom client-side
post-commit-hook
and make every user install it, but this is terrible, isn't it? Git book specifically states that policies should be enforced on server side.
Is there a simple way of achieving something like this? Or is this impossible and it's just git abuse?
...ANSWER
Answered 2018-Jul-16 at 11:55Umm, I'm a bit embarrassed. Apparently this was much easier than I thought. Here is a hasty solution which builds on @wrzasa suggestion:
Clone your repository on the server to which you are pushing, like this (dir.git is a bare repo):
QUESTION
I'm working with a project in a directory called lucy
with a Git subtree called lucy-web
(cf. How can I list the git subtrees on the root?):
ANSWER
Answered 2018-Apr-11 at 09:20git fetch staging master:master
git merge master
QUESTION
I'm trying to use Jenkins to create a special git repository. I created a free-style project that just executes a shell script. When I execute this script by hand, without Jenkins, it works just fine. From Jenkins, however, it behaves quite differently.
...ANSWER
Answered 2018-Jan-10 at 10:001/ Ensure your path is correct, and no quote/double quote escaping occurs in the process of jenkins job starting.
2/ Your command line is a bit too handy to be correctly and safely evaluated.
Put your commands in a regular script, starting with #!/bin/bash
instead of thru the command line.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install git-subtree
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page