TL DR
Using clone / copy
- Pros: The main repo and its clone / copy are silos.
- cons: space inefficiency
Using a branch
- Pros: Space Efficiency (Git branches are cheap)
- cons: relatively cumbersome workflow if you need a lot of clutches
More details
You write
I would like to have at some point a separate copy of my work for experimenting with a few changes. [...] What is the βbestβ way to do this?
You also write in your comment that you are likely to switch between the original work and its βcopyβ without making any changes made in the last.
Here you have different possible approaches; first consider your two sentences, and then explore the third possibility. To fix the ideas, I assume that your repository lives in a directory called main .
1 - use git clone to get a copy of the repository in another directory and use it for playback.
Do you think you could create a clone of main , say, in a directory called exp ,
git clone <path-to-main> <path-to-exp>
and do your crazy experiment in exp . The repo main would be exp "upstream", i.e. exp would display main as one of its remotes called origin . Therefore, if you made more commits in main and wanted to update exp , what happens in main , you can get from main to exp , and then merge or reinstall the latter.
The main problem with this approach is space inefficiency : since the clone carries the entire history of the original repo with it, there will be many duplicate files on your disk. This may or may not be a problem, depending on the size of your source repo, but this is something to consider.
2 - Just cp -r current current git working directory for the new
This is essentially like cloning main , but unless you manually add main as the remote exp device, you cannot get from main to exp . I see no advantage in this approach compared to the first (except, perhaps, that it does not imply the risk of accidentally clicking on things from exp to main ).
3 - Create a new branch directly in the source repo and experiment in it
The third approach is to create a new branch (call it exp ) directly into the main repository,
git branch exp
verify,
git checkout exp
and do an experiment there. The main advantage of this approach compared to the other two is space efficiency: git branches are cheap because creating a new one is not related to copying files.
However, if you make changes and exp unloaded, but donβt commit them, git will consider your working directory βnot cleanβ and will not allow you to return to the master branch until you correct the situation. One way to clean up your repository is to hide your uncommitted changes by running
# while on exp, if there are uncommitted changes git stash save
Then you can go back to master , make some changes, commit them, go back to exp and get your hidden changes by running
git stash pop
If a lot of ticks are involved ( save and pop ), you may find that this workflow is too tedious and cumbersome ...