Git Worktrees Tutorial #3 - Bare Repositories

The Net Ninja · Beginner ·🧠 Large Language Models ·3mo ago

Key Takeaways

This video tutorial covers the concept of bare repositories in Git and how to clone them, demonstrating the use of the git clone command with the --bare flag to create a bare repository without a default work tree.

Full Transcript

Okay then gang in the last lesson we saw how to add a new git work tree to a repo which we cloned on our computer and when we initially cloned that repo git cloned the repository itself the dotgit folder and it also created a default work tree checked out at the latest commit on the main branch from there we then added a second work tree to work on a different feature while we had uncommitted changes in the default work tree however when I'm using work trees a lot in a project I like to work slightly differently and manage my work trees in in a more organized way. And I do that by first of all cloning what's known as a bear repository. So in this lesson we're going to be talking about what a bear repository is and we'll clone a bear repo to our computer as well. Then in the next lesson I'll walk you through the workflow I like to use when I'm working with work trees alongside that bear repository. So then first of all what is a bear repository? Well, like we've already seen when we clone a repo from GitHub to our computer, Git brings down two things, right? The repo itself, which is the git folder and everything inside it, like the branches, the commit history, refs, hooks, etc., and the default work tree, which is the project code checked out at the latest commit normally on the main branch. So, this would represent a standard clone of a repository. Now, when we clone a bare repository, git doesn't create the default work tree and only brings down the contents of the docket folder. And this would now be a bare repo containing no work trees and only the repository data itself. So it still contains all the information like the branches, the history, the refs, all that kind of stuff. But we have no working directory for the project code or no work tree. So the reason I like to use a bear repo when I'm using work trees and I know I'm going to be using them from the start is that it stops me from using the default work tree as a bit of a junk draw. Also, it allows me to organize my work trees in what I think is a much cleaner way by having them sit alongside the docket folder inside a parent folder for the entire project. Whereas in the previous example, when we added a new work tree, we kind of came out of the parent folder, then added it alongside that parent. And to me, that doesn't feel very organized. So, anyway, that's what a bear repo is. Now, let's try cloning one. So, I'm on the same GitHub repo as before, and we're going to clone it in almost the same way as we did before. So, let me grab the repo web URL from down here first. And now in the terminal, I'm currently in the same project directory as before. And if I run the ls command first, you're going to see I already removed the previous clone from the last lesson. So, there's actually nothing in here at the moment. Now, if we were to clone a bear repo directly in here, then it's going to bring down the entire contents of what you normally find inside the do.git folder and it's going to dump all that directly inside this project folder. Now, I don't want to do that. I want to put it inside a specific project folder and then inside agit folder within that. So let me first of all make a new project directory called I don't know portfolio by typing mkdir to make a new directory then portfolio and then I'm going to cd into the portfolio folder. So this is where I want to create the bear repo inside this portfolio directory. And to do that I'm going to type get clone. Then I'm going to paste in the URL and then at the end I'm going to add on the bear flag. So say we only want to clone the bear repo and not create a default work tree. At the end of this I'm going to add a destination path for the bear repo as well which is going to be inside agit folder. Again if I skipped this path part then git is just going to bring down all the repo contents that you normally find inside a dotgit folder and it's going to dump them directly into this project folder. And you might be fine with that. Some other developers work like that. But I put everything inside a dotgit folder just to keep the parent project folder a little bit cleaner. So now I'm going to hit enter to clone it. Okay. So once that's done, I'm going to run the ls command with the a flag to show hidden folders. And we should see that git folder, which we do. Also notice we don't have anything else. Git didn't create a default work tree like before. And there's no project code to speak of yet. I can demo that by trying to run the git status command. And when I do, we should get an error saying that we have to run this command within a work tree, which we don't have yet. Anyway, if we cd into that.git folder, we can then run the ls command again to list the contents of it. And we should see all the same repository data as normal, including all the branch information, history, refs, whatnot. Okay, so let me cd out of this.git folder now back into the project folder. Right. Then, so we've got a bear repo now without any work trees. And we can't work on the code without a work tree.

Original Description

In this series, you’ll learn how to use Git worktrees, a feature that lets you check out multiple branches at the same time in separate working directories. 🍿👇 Get the FULL Git & GitHub Masterclass: https://netninja.dev/p/git-github-masterclass 🍿👇 Get the FULL Claude Code Masterclass: https://netninja.dev/p/claude-code-masterclass 🔥👇 Get access to ALL Masterclasss & premium courses with Net Ninja Pro: https://netninja.dev/p/net-ninja-pro/#prosignup Starter Project: https://github.com/iamshaunjp/portfolio-worktrees
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

This tutorial teaches how to clone a bare repository in Git and manage work trees in a project, covering the git clone command with the --bare flag and repository organization.

Key Takeaways
  1. Clone a repository using the git clone command with the --bare flag
  2. Create a new project directory and navigate to it
  3. Use the ls command to list repository contents
  4. Use the cd command to navigate to the .git folder
  5. Verify the absence of a default work tree by running the git status command
💡 Cloning a bare repository allows for a cleaner project organization by separating the repository data from the work trees.

Related Reads

Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →