Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT - copy newest branch to another directory

Tags:

git

deployment

I read GIT documentation, but couldn't figure out how to just simply copy newest version of code to another directory (or deploy it). Of course I could just simply copy -r code /path/to/another/dir, but then it copies all other files that are created by GIT. And I don't need that. So is there a simple way to just copy raw files without all those hidden files (or copies of original files)?

like image 964
Andrius Avatar asked Aug 14 '13 05:08

Andrius


1 Answers

This is one way to do it:

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

The git archive command is normally to generate an archive file from the content of the repository. It dumps to archive to standard output, which you normally redirect to a file. Here, we subvert the command a bit: instead of redirecting, we immediately extract it, into the specified directory. The target directory must be created first.

That said, you seem to want this for deploying your project. Personally I use Git itself to deploy projects. That way you can upgrade and roll back easily using Git commands. Granted, the .git directory will exist in the deployment directory, on the other hand, a simply copy will not delete files that were removed in the repository, they will remain at the destination.

Finally, you might be interested in my personal favorite: using a post-receive hook to deploy projects remotely.

like image 135
janos Avatar answered Oct 25 '22 14:10

janos