简体   繁体   中英

Clone Git repo with Bash script

I'm diving into the world of Git and my first task is to automate our build process. I'm using Bash since that's what I'm familiar with and it seems to do what I need.

Before I can build my code, I need to clone the latest version of the repo to my PC.

I seem to have a catch 22. I want to clone a repo from a Bash script that would be part of the repo I'm trying to clone.

I want my build/bash script to be under source control along with everything else... But I'd also like a one command operation.

How do others tackle this problem? I'm most familiar with ClearCase so Git is taking some getting used to.

Git clone is analogous to ClearCase mkview in that it creates a new working folder that serves as the main way to interact with files in the repository. If you were writing this script for ClearCase, would you really start by having it create a new ClearCase view? If you did, you'd have the same catch-22 situation.

The common approach is to assume that the clone operation was done as part of one-time setup of this build system, and the script already has access to the working folder. The Git commands you'd be more interested in are clean , checkout , fetch , pull , and reset --hard . There's overlap between Git commands, so you won't need all of these. Obviously the choice of Git commands and the options you'd call them with depends on what you want you want your script to do.

Done that way, there's no problem keeping the script in the repository, except you will wind up versioning it in the same branch(es) as the code you're building. This isn't necessarily bad, but is different from what would (usually) happen in ClearCase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM