-
Notifications
You must be signed in to change notification settings - Fork 26
gcloud setup repository script
By the end of this guide, a repository on Google Cloud will be created in an automated way using a script.
-
Have a Google Cloud project already setup with billing and Cloud Source Repositories API enabled and GCloud CLI installed and configured. If it is not the case, please go back to corresponding guide.
-
Install Git.
The script located at /scripts/repositories/gcloud/create-repo.sh
allows you to either:
-
Create an empty repository with just a README file and clone it to your computer into the directory you set. Useful when starting a project from scratch.
-
Import an already existing directory or Git repository into your project giving a path or an URL. Useful for taking to Google Cloud the development of an existing project.
create-repo.sh \
-a <action> \
-d <local directory> \
-p <project id> \
[-n <repository name>] \
[-g <giturl>] \
[-b <branch>] \
[-r] \
[-s <branch strategy>] \
[-f] \
[--subpath <subpath to import>] \
-a, --action [Required] Use case to fulfil: create, import.
-d, --directory [Required] Path to the directory where your repository will be cloned or initialized.
-p, --project [Required] Short name (ID) of the Google Cloud project.
-n, --name Name for the {provider_name} repository. By default, the source repository or directory name (either new or existing, depending on use case) is used.
-g, --source-git-url Source URL of the Git repository to import.
-b, --source-branch Source branch to be used as a basis to initialize the repository on import, as master branch.
-r, --remove-other-branches Removes branches other than the (possibly new) default one.
-s, --setup-branch-strategy Creates branches and policies required for the desired workflow. Requires -b on import. Accepted values: gitflow.
-f, --force Skips any user confirmation.
--subpath When combined with -g and -r, imports only the specified subpath of the source Git repository.
Tip
|
This is non-exhaustive list. Make your own combination of flags if all of the following use cases does not fit your needs. |
./create-repo.sh -a create -p <project> -n <repository name> -d <local destination directory>
In case repository name is not specified, destination directory name will be used.
./create-repo.sh -a create -p <project> -n <repository name> -d <local destination directory> -s gitflow
./create-repo.sh -a import -g <source git url> -p <project> -n <repository name> -d <local destination directory>
In case repository name is not specified, source repository name (in URL) will be used.
Importing a specific remote Git repository branch as source for a new repository with Gitflow branching strategy
./create-repo.sh -a import -p <project> -g <source git url> -b <source branch> -s gitflow -r -n <repository name> -d <local destination directory>
This will create master
(and develop
since a branching strategy is specified) from the <source branch>
, removing any other branch (including <source branch>
).
./create-repo.sh -a import -p <project> -d <local source directory> -n <repository name>
In case repository name is not specified, source directory name will be used.
Importing a specific local Git repository branch as source for a new repository with Gitflow branching strategy
./create-repo.sh -a 'import' -p <project> -d <local source directory> -b <source branch> -s gitflow -r -n <repository name>
This will create master
(and develop
since a branching strategy is specified) from the <source branch>
, removing any other branch (including <source branch>
).
Warning
|
This operation is destructive regarding branches on the local repository. |
Note
|
Same command could also be used with a local directory, but then using -b and -r would be redundant.
|
To ensure the quality of development, it is crucial to keep a clean Git workflow. The following branching strategies are supported (using -s
flag):
This is not an explanation of Gitflow (there are plenty of them on the web), but the actions performed by the script to help you start using this worflow.
This documentation is licensed under the Creative Commons License (Attribution-NoDerivatives 4.0 International).