032 Introduction to Git Subtrees

  Рет қаралды 39,104

Dan Gitschooldude

Dan Gitschooldude

Күн бұрын

Introduction to the 'git subtree' command. Covers adding a repository as a subtree and updating (reverting) that subtree to an older state. Subtrees are a way to track other git repos as dependencies of your own. They provide the same mechanism as Git Submodules but with a different approach.
See also:
Introduction to Git Submodules: • 008 Introduction to Gi...
More about Git Submodules: • 009 More about git sub...
If you are looking for an effective concise introduction to Git, I highly recommend my "Fundamentals of Git" course on Udemy: www.udemy.com/course/fundamen...
If you or your company is interested in live virtual software and tools training, see www.continuoustech.net/training/ for a list of training topics we offer.

Пікірлер: 34
@DanGitschooldude
@DanGitschooldude 3 жыл бұрын
Correction near 5:50 the second command (that I didn't even execute) should read 'git merge trick/master' not 'git merge origin/master'
@PhilippeCarphin
@PhilippeCarphin Жыл бұрын
You would also be required to add --allow-unrelated-histories in the merge command. I used that particular command to merge git repositories while preserving their individual histories. I didn't use git-subtree because we abandoned the original repositories.
@leoclub626
@leoclub626 5 жыл бұрын
It would be great if you begin your videos with a summary of why this features exists in the first place, what's the use of it etc. Love your tutorials.
@DanGitschooldude
@DanGitschooldude 5 жыл бұрын
Thanks for the feedback!
@jasonsoto5273
@jasonsoto5273 4 жыл бұрын
Very clear and understandable video!
@danielhaile9073
@danielhaile9073 4 жыл бұрын
Thanks for sharing it really help me while really concerning not loose the history of the log .
@nikhileshsaggere
@nikhileshsaggere 3 жыл бұрын
Pls provide explaination on the git subtree split and git push subtree... thanks for the excellent content 🙏🏻
@rafaelvelazco8970
@rafaelvelazco8970 Жыл бұрын
Great Video! Very useful, thanks for sharing.
@Tatulak
@Tatulak 2 жыл бұрын
i'm quite of sad there is not a subtree push video
@samuelcasimiro
@samuelcasimiro Жыл бұрын
Wow. The most transparent subtree explanation I have ever seen. Thank you so much! I will definitely subscribe.
@flaviocampelo
@flaviocampelo 3 жыл бұрын
Hi, amazing! Could you show us more about git subtree split and how to push just subtree and how to push the parent project?
@JRO98726
@JRO98726 2 жыл бұрын
please pt2 for the git subtree commands!, this is very interesting. I want to know how to use subtrees tu push changes to several git repos, git pulls and so on...
@ruixue6955
@ruixue6955 11 күн бұрын
0:56 git remote show origin 2:13 git subtree add
@1985stout
@1985stout Жыл бұрын
Thankyou!!
@Mr-lw7gy
@Mr-lw7gy 2 жыл бұрын
That was extremely informative and nothing like seeing it in action. Now time to get my hands dirty and use this. Also curious if there is a way for another user to pull down the refs to provide the history. I can see that being pretty valuable from time to time.
@kopiking352
@kopiking352 Жыл бұрын
using --squash would cause lots of merge conflicts when subtree add or pull
@2sourcerer
@2sourcerer 5 жыл бұрын
Thanks for the tutorial. Other than git submodule and git subtree, I'm also checking out Git subrepo. The graph of the history however, is currently really beyond my understanding. It would be nice if git subrepo is covered as well.
@geethasweet5929
@geethasweet5929 4 жыл бұрын
@Dan Gitschooldude What if we have to clone project to existing directory and make it as subdirectory
@hicnar
@hicnar 3 жыл бұрын
Great vids Dan! I am just wondering if there's a way to subtree only selected directories from the trick repo? In my scenario, I have a private repo on Github which I kinda want to keep private, except the web directory that I would like to expose to webdevs. The logic that renders the web layer in the project lives in my private repo, but the webdevs will need to have some basic logic that can render the pages stored in the web directory they will work on, so the subtree looks like something I could use if I move the web directory to a separate repo, but in all subtree examples I have seen so far it is the contents of the whole repository that get included with subtree and it does not look like I can pick some directories and omit others. Or perhaps there's a way to do this? Any hints will be appreciated!
@DanGitschooldude
@DanGitschooldude 3 жыл бұрын
You can split the history of a repository out by directory, but that creates a brand new repo and isn't a subtree mechanism. See this vid: kzfaq.info/get/bejne/hpuiks2As9_ZeKM.html If you split your repo as desired, then you could easily make the public part a subtree of another project, if that's what you're ultimately after. Thanks for watching!
@nelsonschwarz1790
@nelsonschwarz1790 2 жыл бұрын
Hi Dan! Thanks for the great video. I have a quick question: is it best practice to keep the sub-project commits as part of parent's repository commit history? I have read it is best practice to keep super and sub-project code organized in separate commits. If a commit only contains changes to sub-project code, why should it stay as part of the parent history? If it shouldn't, what would be the best way to clean them from the log? Thanks!
@DanGitschooldude
@DanGitschooldude 2 жыл бұрын
Good question and this is a topic of much debate. My preference is always to avoid subtrees and submodules if at all possible and just use a monorepo. There's so much more work when trying to break code out into separate repos and track that content at the super project level. The feasibility of that workflow is very project specific, so unfortunately I can't really recommend the best approach without talking to you about your project for about an hour lol. Thanks for watching!
@JordanShackelford
@JordanShackelford 2 жыл бұрын
Hey so I have a git repo called Projects where I have a bunch of subfolders with small toy projects. This repo includes my portfolio. How can I host my portfolio on heroku without having to include the entire repo?
@evelynlima5616
@evelynlima5616 Жыл бұрын
what about git subtree push? you know now that we have the trick subtree how can we maintain it if needed?
@saadurrehmanmohsin8304
@saadurrehmanmohsin8304 4 жыл бұрын
Is there a way we can copy the same directory structure while creating a subtree. Right now if I use the subtree command it creates a folder and then copy all the code inside the folder. I dont want to do that and I want to keep the same directory structure and copy in the main folder
@DanGitschooldude
@DanGitschooldude 4 жыл бұрын
I don't think subtrees support that, but you could literally just merge two repos together and you'll end up with both repo's top level directory structure interleaved together. Of course then you can't push to the subtree remote anymore, not sure if that's a problem for your use case. Thanks for watching!
@saadurrehmanmohsin8304
@saadurrehmanmohsin8304 4 жыл бұрын
@@DanGitschooldude do you have a demo for merging repository your demo on subtree really helped a lot
@DanGitschooldude
@DanGitschooldude 4 жыл бұрын
I dont have a video on it, but all you do is make one repo a remote of the other and then git merge one branch into another. You can merge any two git repos even if they have no common commits.
@alexisfrjp
@alexisfrjp 2 жыл бұрын
What if trick's master branch has changed when I clone the mysim repo? It isn't automatically update trick, right? I can't see the advantage... I don't want to have all the trick's files in my mysim repo...
@DanGitschooldude
@DanGitschooldude 2 жыл бұрын
The subtree state will be consistent in the mysim repo after it's been imported. Subsequent clones of mysim will get the same state of trick as when it was first imported. It will stay the same until the subtree is updated and that state is shared via push/merge with others. If you choose not to track trick at all, different developers could be using different states of trick, which could be a problem depending on your workflow.
@alainachkar9888
@alainachkar9888 2 жыл бұрын
Thanks for a great explanation of git subtrees and git submodules. I had never understood them with such great depth before. If we have a software project which consists of two (or more) "pieces", say one piece is a Chrome Extension, another piece is a CLI (which in this case is written as a Ruby gem, but it could be written as a Node.js module), such that the 2 pieces share common messaging between them, such that new features (i.e. messages) are being added historically in time, would you suggest to have : (A) the 2 pieces in 2 separate git repos, and keep them in sync using the same git tags in each, (B) have a super-project and add these 2 pieces as submodules or subtrees in the super-project, or (C) have one repo and put these 2 pieces simply as 2 subdirectories ? Both pieces are not "slow-moving 3rd party dependencies" but they are actually fast moving co-dependent projects.
@DanGitschooldude
@DanGitschooldude 2 жыл бұрын
C. I always recommend fewer repos if possible. Submodules are often (mis)used as a way to separate logically different content but that's usually a poor decision. Things that need each other to test should live in the same top level project unless there's a good reason they can't. Thanks for the kind words!
@DzintarsDev
@DzintarsDev 9 ай бұрын
@@DanGitschooldude IMHO it strongly depends on a tooling at your exposure. From a single developer viewpoint I would agree. From an enterprise PoV with thousands of repositories, this would be bad from many different points. Licensing, compliance, security, etc, etc. There are tools to handle submodules. Zuul CI, Bazel, Gerrit, Repo, Jiri, etc. They are designed to work with a ton of separate repositories while on a surface they "feels" (DX) like a single monorepo.
033 Introduction to Docker and Gitlab Registry PART (1/2)
14:42
Dan Gitschooldude
Рет қаралды 23 М.
008 Introduction to Git Submodules
26:52
Dan Gitschooldude
Рет қаралды 70 М.
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 10 МЛН
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 38 МЛН
Что такое Git flow и когда использовать?
11:44
PurpleSchool | Anton Larichev
Рет қаралды 62 М.
Introduction to Git - Core Concepts
28:37
David Mahler
Рет қаралды 341 М.
13 Advanced (but useful) Git Techniques and Shortcuts
8:07
Fireship
Рет қаралды 897 М.
Git Tutorial: All About Submodules
3:13
GitKraken
Рет қаралды 98 М.
Neovim and Git: SOLVED
8:03
typecraft
Рет қаралды 61 М.
What is a bare Git repo and why you need them
5:55
Engineer Man
Рет қаралды 65 М.
Git for Beginners: Best Practices for Teams (Part 7)
11:01
Self Teach Me
Рет қаралды 10 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
Git From the Bits Up
55:45
InfoQ
Рет қаралды 95 М.
Learn Git Rebase in 6 minutes // explained with live animations!
6:43
The Modern Coder
Рет қаралды 773 М.