Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Copy a version for playing around

While developing an application, I would like to have at one point a separate copy of my work for experimenting with several changes. Theses changes are not meant to be committed! It's just playing around, to try out various possibilities.

What is the "best" way to do this? I found the following possibilities, but would like to get the advice of people who have more experience with git than I do:

  1. I could use git clone to get a copy of the repository into a different directory, and use it to play around.
  2. I could just cp -r my current git working directory to the new one.

In case (1), git is aware about the clone, and I could later rebase if I really would want to, but it is unlikely that I will ever do this.

In this case, is there something I should be aware of, which makes either solution (1) or (2) preferable? Or is there an even better way to do it?

like image 763
user1934428 Avatar asked Aug 30 '14 12:08

user1934428


People also ask

Can I just copy a git repository?

Yes you can, but there's no need to copy the full working tree. You can copy just the . git folder without the working tree (i.e. as a "bare" repo) and then checkout the latest working tree on the other machine.


Video Answer


1 Answers

The best way is to create your own branch from the current state, do your work on this branch (with commiting if you want). At the end, if you want to have your work with the main branch, you could run a git merge.

To create a branch from the current state, just run git checkout -b my_branch

like image 146
GHugo Avatar answered Oct 26 '22 23:10

GHugo