Lädt...

🔧 Working on mulitple braches at once using git worktree


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Working on multiple branches at once

Git worktree enables you to have multiple working directories linked to the same repository. Each directory can have its own branch checked out. And you can edit the code for each feature without changing or stashing the changes you did on each branch.

Worktree creation

The following command will create a new directory, debug with branch1 checked out.

You can browse the ../debug directory and change the code as per your development for branch1.

git worktree add ../debug branch1

pwd
echo somenewfeature on branch 1 > somenewfeature
cat somenewfeature

/home/cold/Projects/Personal/gitworktreedemo/debug
somenewfeature on branch 1

In the meanwhile you can keep editing the root directory with the main branch.

pwd
echo somenewfeature on main 1 > somenewfeatureonmain
cat somenewfeatureonmain

/home/cold/Projects/Personal/gitworktreedemo/main
somenewfeature on main 1

You can run the git commands going inside each directory.

pwd
git add .
git status

/home/cold/Projects/Personal/gitworktreedemo/main
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    new file: somenewfeatureonmain


pwd
git add .
git status

/home/cold/Projects/Personal/gitworktreedemo/debug
On branch branch1
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    new file: somenewfeature

List existing worktrees

You can list your worktrees from the main as well as the debug directories.

git worktree list

/home/cold/Projects/Personal/gitworktreedemo/main e0ccbca [main]
/home/cold/Projects/Personal/gitworktreedemo/debug 42ad28a [branch1]

Remove a worktree

When you are finally done with the feature branch, you can delete the worktree using remove command.

git worktree remove ../debug
ls ..
git worktree list

main
/home/cold/Projects/Personal/gitworktreedemo/main e0ccbca [main]

Any commit you did on the feature branch will automatically be reflected in the main codebase.

git checkout branch1
git log --oneline

A   somenewfeatureonmain
82cad2d done
42ad28a A commit on branch1
e0ccbca A commit on main

Advice on working with worktrees

As the new directory will not be ignored by default, it is best to create your worktree directories out of git root

The way I create my worktrees is I create a new directory with project name. Then I clone my actual repository inside this directory and keep my worktrees on the same level as project.

For example, my main project is cloned inside main directory and I created debug directory in the same level as main.

tree .

.
├── debug
│   └── somenewfeature
└── main
    └── somenewfeatureonmain

2 directories, 2 files

...

🔧 Working on mulitple braches at once using git worktree


📈 132.97 Punkte
🔧 Programmierung

🔧 🚀 Simplify your git workflow with Git Worktree!


📈 42.27 Punkte
🔧 Programmierung

🔧 How to work on multiple branches using git worktree command?


📈 38.58 Punkte
🔧 Programmierung

🔧 What to do when your git worktree is not detecting file changes


📈 34.86 Punkte
🔧 Programmierung

🔧 Unlocking the Power of Git Worktree: A Game-Changer for Developers 🚀


📈 34.86 Punkte
🔧 Programmierung

🔧 Save your life with Git Worktree


📈 34.86 Punkte
🔧 Programmierung

🔧 Git Worktree: Your Ticket to Parallel Development Paradise


📈 34.86 Punkte
🔧 Programmierung

🔧 Trabalhe com duas branches ou mais ao mesmo tempo com Git Worktree


📈 34.86 Punkte
🔧 Programmierung

🎥 HPR3307: Git worktree


📈 34.86 Punkte
🎥 Podcasts

🔧 DAY 5 Git rebase, Git stash, Git cherry-pick.


📈 22.21 Punkte
🔧 Programmierung

🔧 Git Rebase and Git stash and Git pop -day 4


📈 22.21 Punkte
🔧 Programmierung

🔧 Ditch Git Checkout: Use Git Switch and Git Restore Instead


📈 22.21 Punkte
🔧 Programmierung

🔧 Restaurando e Alternando Branches com Git: Domine os Comandos git restore e git switch


📈 22.21 Punkte
🔧 Programmierung

🎥 Top Git Commands | Most Used Git Commands | Git Commands With Examples


📈 22.21 Punkte
🎥 Video | Youtube

🔧 git switch and git checkout – How to switch branches in git


📈 22.21 Punkte
🔧 Programmierung

🔧 GIT: Pulling and Pushing Commits Using Git


📈 18.53 Punkte
🔧 Programmierung

🔧 How to create "Code Resume"using index.html from Git-Bash to Git-Hub


📈 18.53 Punkte
🔧 Programmierung

🔧 please stop using git checkout! Learn to use the right git commands


📈 18.53 Punkte
🔧 Programmierung

🔧 Automatically Prefix JIRA Issue ID to Git Commit Messages using Git Hooks


📈 18.53 Punkte
🔧 Programmierung

🔧 Git - Using git cherry-pick to Select Specific Commits


📈 18.53 Punkte
🔧 Programmierung

🔧 Using git and git hub


📈 18.53 Punkte
🔧 Programmierung

🔧 Using git Conditionals to Manage Your Git Identities


📈 18.53 Punkte
🔧 Programmierung

🔧 Git Command Line Mastery: 10 Essential Commands for Version Control Using Git


📈 18.53 Punkte
🔧 Programmierung

🔧 How to push large files to git repository using Git LFS


📈 18.53 Punkte
🔧 Programmierung

🔧 Are you still using git checkout for everything? It is time to switch to git switch


📈 18.53 Punkte
🔧 Programmierung

🔧 Git Gud: Survive your 1st Month of Using Git 🚀


📈 18.53 Punkte
🔧 Programmierung

📰 Unix Legend Adding Unicode Support To AWK - Once He Figures Out Git


📈 18.44 Punkte
📰 IT Security Nachrichten

📰 Once uBlock Origin stops working on Chrome, you have 2 options


📈 17.65 Punkte
📰 IT Nachrichten

🔧 Working together has once again proven what a professional and dedicated team you are.


📈 17.65 Punkte
🔧 Programmierung