Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git worktree allow "pulling" from a different worktree?

I am working on the main worktree to test my own code for unit tests. I created another work tree (let's call it integration) to build a bigger executable as my own code is just a dependency so the 2nd work tree is for something like an integration test.

As I work on my main worktree, I discover that I would like to add more logs in the unit tests to figure out what might be wrong. I also think that these logs would be good in the integration tests as well and would like to update my worktree with the most recent changes in main.

Is there a way to update the integration worktree with something similar to git pull from main? Something that would look like git worktree pull? If not, is there a workaround as I don't see anything remotely like it in the docs?

I don't like the idea of creating a new worktree every time I could have done something like git worktree pull.

NOTE: I don't want to commit changes just yet because nothing is confirmed as working correctly.

I didn't undestand what this user is trying to do here and I am not working with submodules.

like image 639
heretoinfinity Avatar asked Oct 12 '25 12:10

heretoinfinity


1 Answers

I recommend using git diff and git apply

git diff creates a "diff file" for your current worktree.
git apply applies a diff file to the current worktree

This is the best way to copy uncommitted changes from one worktree to another.

Example:

cd /git/main 
git diff > /path/to/difffile
cd /git/integration
git apply /path/to/difffile

Note: You can also specify the files you want to include in the diff, if you do not want to copy the changes from all files, only some:

git diff -- file1 subdir/file2 > /path/to/difffile
like image 109
David Sugar Avatar answered Oct 14 '25 06:10

David Sugar