GIT - copy newest branch to another directory

deployment, git

Solution

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.

Problem

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)?

Original source

Related problems