Skip to content

Copy directory from repository to local folder #23772

Discussion options

You must be logged in to vote
heinzituberkel:

How can I copy files from a certain revision of the repository to some local directory without destroying the contents of my working directory?

The git worktree command can do what you want. E.g. if your current directory is your existing repository, and you want the branch some-branch in a directory named repo-some-branch next to your primary directory:

git worktree add ../repo-some-branch some-branch

The new directory is bound to your repository for the git data, but the checkout is independent, so you can copy files and commit on either side as usual. You could also use this to work on two branches separately.

Note however that if you want to fully merge the branc…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants