git-subtree | experimental alternative to the git-submodule command

 by   apenwarr Shell Version: v0.4 License: GPL-2.0

kandi X-RAY | git-subtree Summary

kandi X-RAY | git-subtree Summary

git-subtree is a Shell library. git-subtree has no bugs, it has no vulnerabilities, it has a Strong Copyleft License and it has medium support. You can download it from GitHub.

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

            kandi-support Support

              git-subtree has a medium active ecosystem.
              It has 1348 star(s) with 136 fork(s). There are 44 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              git-subtree has no issues reported. There are 9 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of git-subtree is v0.4

            kandi-Quality Quality

              git-subtree has no bugs reported.

            kandi-Security Security

              git-subtree has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              git-subtree is licensed under the GPL-2.0 License. This license is Strong Copyleft.
              Strong Copyleft licenses enforce sharing, and you can use them when creating open source projects.

            kandi-Reuse Reuse

              git-subtree releases are not available. You will need to build from source code and install.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of git-subtree
            Get all kandi verified functions for this library.

            git-subtree Key Features

            No Key Features are available at this moment for git-subtree.

            git-subtree Examples and Code Snippets

            No Code Snippets are available at this moment for git-subtree.

            Community Discussions

            QUESTION

            Join history of older version of the same repository
            Asked 2020-Sep-19 at 02:26

            I had a repository with this history:

            ...

            ANSWER

            Answered 2020-Jun-19 at 05:59

            You can create a new repo, add both repositories as remotes, and rebase the second onto the first:

            Here's repo 1:

            Source https://stackoverflow.com/questions/62463058

            QUESTION

            Difference between git filter-branch subdirectory-filter & git subtree split -P
            Asked 2020-Apr-11 at 01:03

            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:03

            The 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.

            More details

            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.

            Source https://stackoverflow.com/questions/61127751

            QUESTION

            How do I "reverse" a gitignore file pattern in a subtree subdirectory?
            Asked 2020-Feb-21 at 20:29

            I have a repo that contains a subtree that has some build and config files.

            ...

            ANSWER

            Answered 2020-Feb-21 at 20:29

            It'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.

            https://git-scm.com/docs/gitignore

            Source https://stackoverflow.com/questions/60143485

            QUESTION

            How to share source code library between several solutions in different repositories?
            Asked 2019-May-11 at 21:48

            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:48

            I 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

            Source https://stackoverflow.com/questions/43164316

            QUESTION

            "git does not look like a ref" trying to link a local branch to a remote Heroku app
            Asked 2019-Apr-01 at 16:58

            I've set up a Heroku app, lucy-staging:

            ...

            ANSWER

            Answered 2019-Apr-01 at 16:58

            I managed to push the subtree to the master branch of the remote using the following command:

            Source https://stackoverflow.com/questions/49244934

            QUESTION

            Merge 2 Rails App subdirectories keeping git history
            Asked 2018-Aug-03 at 10:32

            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:46

            I would recommend following the merge-and-move strategy instead of subtree: to me, it keeps the history clearer (and unchanged).

            1. Move the directories around in the source repository to produce the shape you want (deleting any files you don't want to bring across)
            2. Commit that (on a temporary branch if you like)
            3. Add the source repository as a remote in the target checkout
            4. Merge the relevant branch from source into target, and commit
            5. 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

            Source https://stackoverflow.com/questions/51649427

            QUESTION

            How to have a tracked file in a git repo that doesn't change from branch to branch
            Asked 2018-Jul-30 at 00:23
            What I’m sort of looking for:

            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).
            Possible (but rejected) solutions: Worktree

            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.

            Submodule

            Thinking 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.

            Subtree

            Unless 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 branch

            While 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/Meta

            At 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 repo

            While 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:23

            I 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 concept

            The 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 repo

            Source https://stackoverflow.com/questions/51549176

            QUESTION

            Git: is there a way to auto push a subtree?
            Asked 2018-Jul-16 at 11:55

            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:55

            Umm, I'm a bit embarrassed. Apparently this was much easier than I thought. Here is a hasty solution which builds on @wrzasa suggestion:

            1. Clone your repository on the server to which you are pushing, like this (dir.git is a bare repo):

            Source https://stackoverflow.com/questions/46714487

            QUESTION

            How to integrate remote changes before pushing to Heroku
            Asked 2018-Apr-11 at 09:20

            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:20
            git fetch staging master:master
            git merge master
            

            Source https://stackoverflow.com/questions/49764246

            QUESTION

            Shell script run by Jenkins creates non-terminating process
            Asked 2018-Jan-12 at 08:49

            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:00

            1/ 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.

            Source https://stackoverflow.com/questions/48184515

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install git-subtree

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/apenwarr/git-subtree.git

          • CLI

            gh repo clone apenwarr/git-subtree

          • sshUrl

            git@github.com:apenwarr/git-subtree.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Shell Libraries

            awesome

            by sindresorhus

            ohmyzsh

            by ohmyzsh

            realworld

            by gothinkster

            nvm

            by nvm-sh

            papers-we-love

            by papers-we-love

            Try Top Libraries by apenwarr

            sshuttle

            by apenwarrPython

            redo

            by apenwarrPython

            blip

            by apenwarrJavaScript

            git-subtrac

            by apenwarrGo

            gitbuilder

            by apenwarrPerl