Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout from a specific directory

When we build our application, we fetch code from a directory of a CVS repository first then build it. So in Git, do we have anything similar to do it. I just want to checkout from a specfic diectory of Git repo and then build our code. No local repo maintainance, nothing. Just code checkout.

I know there is something called "Sparse checkout". Do we have anything simpler?

My problem is that this build script can be run on any server. So if I choose Sparse checkout, I will have to go on each server ,set-up Git and and tell it how to do sparse checkout.

like image 747
Ahmad Avatar asked Feb 15 '23 19:02

Ahmad


1 Answers

Git philosophy is miles away from CVS, so I suggest you to act differently here. Your Git repositories will be distributed, every developper or server will have a copy of it, with one being authoritative among these (origin remote in Git terms).

When you want to start a build from a fresh checkout, you first say Git to grab the latest changes from origin, this is called a fetch.

git fetch origin

Then, to have a fresh checkout, you want your filesystem to be exactly the same as the server version, without any other file.

git checkout --force origin/master
git clean -d --force

The advantage here is that the network operation is very efficient, you grab only the latest diffs from the server you want to sync with, and you're still sure that you're building from the right files, without them being changed.

You'll want to check also tools for Continuous Integration, like Jenkins, which quite well integrated with Git repositories.

like image 100
CharlesB Avatar answered Feb 18 '23 10:02

CharlesB