Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout without clone

I am very much new to Git. Can anyone help me understand the follwoing.

  1. I am working on a build script that first checks out/update code from remote repository. I have nothing to do with the local machine . Do still I need to clone the remote repo in my local and checkout code afterwards.
  2. If I clone a repository, does it copy entire code from repo and consume storage on local machine.
  3. If I really need to clone first then checkout/update, in my build script, how will I check (from Python or ANT)that the repository is cloned or not.
like image 568
Ahmad Avatar asked Jul 22 '13 16:07

Ahmad


2 Answers

I've found a very helpful git clone syntax for doing builds where you do not need the entire git history of revisions. Note that this seems to require Git version 1.9+:

git clone -b <remoteBranch> --single-branch --depth 1 ssh://[email protected]:serverport/PathToProject <FolderName>

Notes:

This clones and checks out "remoteBranch" without the other branches, at a depth of 1 (so only the most recent file snapshots) into the folder "FolderName"

like image 149
Michael Butler Avatar answered Oct 04 '22 21:10

Michael Butler


  1. yes
  2. yes
  3. check if the .git directory exists.

See CharelsB’s comment for tips on how to get more detailed answers ;).

like image 45
Chronial Avatar answered Oct 04 '22 23:10

Chronial