GIT - copy a new branch to another directory

I read the GIT documentation but couldn't figure out how easy it is to copy a new version of the code to another directory (or deploy it). Of course, I could just just copy -r code /path/to/another/dir , but then it copies all the other files created using GIT. And I don’t need it. So, is there an easy way to just copy the raw files without all the hidden files (or copies of the source files)?

+4
source share
2 answers

This is one way to do this:

 mkdir /path/to/target/dir git archive master | tar x -C /path/to/target/dir 

Typically, the git archive command creates an archive file from the contents of the repository. It dumps the archive into standard output, which you usually redirect to a file. Here we reject the command a bit: instead of redirecting, we immediately extract it to the specified directory. The target directory must be created first.

However, you seem to need this to deploy your project. Personally, I use Git to deploy projects. This way you can easily update and roll back using Git commands. Of course, the .git directory will exist in the deployment directory, on the other hand, just a copy will not delete files that were deleted in the repository, they will remain at the destination.

Finally, you may be interested in my personal favorite: using post-receive tags to deploy projects remotely .

+4
source

Option 1: Exclude the .git Subdirectory

Assuming you have the default setting for your Git repository, you can just copy everything into your project, but exclude the .git subdirectory.

Obviously, you can do this with a bash terminal using rsync :

 rsync -av --exclude='.git' source destination 

but I'm not sure how you could do this with Windows copy .

Option 2: Git export archive

Another option is to use git archive :

 git archive --format zip --output "output.zip" master -0 

will provide you with an uncompressed archive ( -0 is the uncompressed flag). The problem is that you need to extract files from the archive.

If you have access to Unix tools in the form of a bash or Cygwin shell, you can also use these Unix tools in janos answer . See Also How to export git (for example, "export svn") .

# Option 3: Use Git ls-files

There are problems with this, because I am passing the cp arguments in the wrong order (files as destination directories instead of sources), so clean this up for now.

Another option is to get a list of all the files that Git tracks in your working copy, and then pass them as an argument to the copy command. Here is an example with Unix cp :

 git ls-files | xargs cp <destination-root> 
+4
source

Source: https://habr.com/ru/post/1496958/


All Articles