salt.modules.git

Support for the Git SCM

salt.modules.git.add(cwd, file_name, user=None, opts=None)

add a file to git

cwd
The path to the Git repository
file_name
Path to the file in the cwd
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.add /path/to/git/repo /path/to/file
salt.modules.git.archive(cwd, output, rev='HEAD', fmt=None, prefix=None, user=None)

Export a tarball from the repository

cwd
The path to the Git repository
output
The path to the archive tarball
rev: HEAD
The revision to create an archive from
fmt: None
Format of the resulting archive, zip and tar are commonly used
prefix : None
Prepend <prefix>/ to every filename in the archive
user : None
Run git as a user other than what the minion runs as

If prefix is not specified it defaults to the basename of the repo directory.

CLI Example:

salt '*' git.archive /path/to/repo /path/to/archive.tar.gz
salt.modules.git.branch(cwd, rev, opts=None, user=None)

Interacts with branches.

cwd
The path to the Git repository
rev
The branch/revision to be used in the command.
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.branch mybranch --set-upstream-to=origin/mybranch
salt.modules.git.checkout(cwd, rev, force=False, opts=None, user=None)

Checkout a given revision

cwd
The path to the Git repository
rev
The remote branch or revision to checkout
force : False
Force a checkout even if there might be overwritten changes
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Examples:

salt '*' git.checkout /path/to/repo somebranch user=jeff

salt '*' git.checkout /path/to/repo opts='testbranch -- conf/file1 file2'

salt '*' git.checkout /path/to/repo rev=origin/mybranch opts=--track
salt.modules.git.clone(cwd, repository, opts=None, user=None, identity=None, https_user=None, https_pass=None)

Clone a new repository

cwd
The path to the Git repository
repository
The git URI of the repository
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as
identity : None
A path to a private key to use over SSH
https_user : None

HTTP Basic Auth username for HTTPS (only) clones

New in version 20515.5.0.

https_pass : None

HTTP Basic Auth password for HTTPS (only) clones

New in version 2015.5.0.

CLI Example:

salt '*' git.clone /path/to/repo git://github.com/saltstack/salt.git

salt '*' git.clone /path/to/repo.git\
        git://github.com/saltstack/salt.git '--bare --origin github'
salt.modules.git.commit(cwd, message, user=None, opts=None)

create a commit

cwd
The path to the Git repository
message
The commit message
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.commit /path/to/git/repo 'The commit message'
salt.modules.git.config_get(cwd=None, setting_name=None, user=None)

Get a key or keys from the git configuration file (.git/config).

cwd : None

Optional path to a Git repository

Changed in version 2014.7.0: Made cwd optional

setting_name : None
The name of the configuration key to get. Required.
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.config_get setting_name=user.email
salt '*' git.config_get /path/to/repo user.name arthur
salt.modules.git.config_set(cwd=None, setting_name=None, setting_value=None, user=None, is_global=False)

Set a key in the git configuration file (.git/config) of the repository or globally.

cwd : None

Options path to the Git repository

Changed in version 2014.7.0: Made cwd optional

setting_name : None
The name of the configuration key to set. Required.
setting_value : None
The (new) value to set. Required.
user : None
Run git as a user other than what the minion runs as
is_global : False
Set to True to use the '--global' flag with 'git config'

CLI Example:

salt '*' git.config_set /path/to/repo user.email me@example.com
salt.modules.git.current_branch(cwd, user=None)

Returns the current branch name, if on a branch.

CLI Example:

salt '*' git.current_branch /path/to/repo
salt.modules.git.describe(cwd, rev='HEAD', user=None)

Returns the git describe string (or the SHA hash if there are no tags) for the given revision

cwd
The path to the Git repository
rev: HEAD
The revision to describe
user : None
Run git as a user other than what the minion runs as

CLI Examples:

salt '*' git.describe /path/to/repo

salt '*' git.describe /path/to/repo develop
salt.modules.git.fetch(cwd, opts=None, user=None, identity=None)

Perform a fetch on the given repository

cwd
The path to the Git repository
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as
identity : None
A path to a private key to use over SSH

CLI Example:

salt '*' git.fetch /path/to/repo '--all'

salt '*' git.fetch cwd=/path/to/repo opts='--all' user=johnny
salt.modules.git.init(cwd, opts=None, user=None)

Initialize a new git repository

cwd
The path to the Git repository
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.init /path/to/repo.git opts='--bare'
salt.modules.git.ls_remote(cwd, repository='origin', branch='master', user=None, identity=None, https_user=None, https_pass=None)

Returns the upstream hash for any given URL and branch.

cwd
The path to the Git repository
repository: origin
The name of the repository to get the revision from. Can be the name of a remote, an URL, etc.
branch: master
The name of the branch to get the revision from.
user : none
run git as a user other than what the minion runs as
identity : none
a path to a private key to use over ssh
https_user : None

HTTP Basic Auth username for HTTPS (only) clones

New in version 2015.5.0.

https_pass : None

HTTP Basic Auth password for HTTPS (only) clones

New in version 2015.5.0.

CLI Example:

salt '*' git.ls_remote /pat/to/repo origin master
salt.modules.git.merge(cwd, branch='@{upstream}', opts=None, user=None)

Merge a given branch

cwd
The path to the Git repository
branch : @{upstream}
The remote branch or revision to merge into the current branch
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.fetch /path/to/repo
salt '*' git.merge /path/to/repo @{upstream}
salt.modules.git.pull(cwd, opts=None, user=None, identity=None)

Perform a pull on the given repository

cwd
The path to the Git repository
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as
identity : None
A path to a private key to use over SSH

CLI Example:

salt '*' git.pull /path/to/repo opts='--rebase origin master'
salt.modules.git.push(cwd, remote_name, branch='master', user=None, opts=None, identity=None)

Push to remote

cwd
The path to the Git repository
remote_name
Name of the remote to push to
branch : master
Name of the branch to push
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as
identity : None
A path to a private key to use over SSH

CLI Example:

salt '*' git.push /path/to/git/repo remote-name
salt.modules.git.rebase(cwd, rev='master', opts=None, user=None)

Rebase the current branch

cwd
The path to the Git repository
rev : master
The revision to rebase onto the current branch
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.rebase /path/to/repo master
salt '*' git.rebase /path/to/repo 'origin master'

That is the same as:

git rebase master
git rebase origin master
salt.modules.git.remote_get(cwd, remote='origin', user=None, redact_auth=True)

get the fetch and push URL for a specified remote name

remote : origin
the remote name used to define the fetch and push URL
user : None
Run git as a user other than what the minion runs as
redact_auth : True

Set to False to include the username/password if the remote uses HTTPS Basic Auth. Otherwise, this information will be redacted.

Warning

Setting this to False will not only reveal any HTTPS Basic Auth that is configured, but the return data will also be written to the job cache. When possible, it is recommended to use SSH for authentication.

New in version 2015.5.6.

CLI Example:

salt '*' git.remote_get /path/to/repo
salt '*' git.remote_get /path/to/repo upstream
salt.modules.git.remote_set(cwd, name='origin', url=None, user=None, https_user=None, https_pass=None)

sets a remote with name and URL like git remote add <remote_name> <remote_url>

remote_name : origin
defines the remote name
remote_url : None
defines the remote URL; should not be None!
user : None
Run git as a user other than what the minion runs as
https_user : None

HTTP Basic Auth username for HTTPS (only) clones

New in version 2015.5.0.

https_pass : None

HTTP Basic Auth password for HTTPS (only) clones

New in version 2015.5.0.

CLI Example:

salt '*' git.remote_set /path/to/repo remote_url=git@github.com:saltstack/salt.git
salt '*' git.remote_set /path/to/repo origin git@github.com:saltstack/salt.git
salt.modules.git.remotes(cwd, user=None, redact_auth=True)

Get remotes like git remote -v

cwd
The path to the Git repository
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.remotes /path/to/repo
salt.modules.git.reset(cwd, opts=None, user=None)

Reset the repository checkout

cwd
The path to the Git repository
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.reset /path/to/repo master
salt.modules.git.revision(cwd, rev='HEAD', short=False, user=None)

Returns the long hash of a given identifier (hash, branch, tag, HEAD, etc)

cwd
The path to the Git repository
rev: HEAD
The revision
short: False
Return an abbreviated SHA1 git hash
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.revision /path/to/repo mybranch
salt.modules.git.rm(cwd, file_name, user=None, opts=None)

Remove a file from git

cwd
The path to the Git repository
file_name
Path to the file in the cwd
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.rm /path/to/git/repo /path/to/file
salt.modules.git.stash(cwd, opts=None, user=None)

Stash changes in the repository checkout

cwd
The path to the Git repository
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.stash /path/to/repo master
salt.modules.git.status(cwd, user=None)

Return the status of the repository. The returned format uses the status codes of git's 'porcelain' output mode

cwd
The path to the Git repository
user : None
Run git as a user other than what the minion runs as

CLI Example:

salt '*' git.status /path/to/git/repo
salt.modules.git.submodule(cwd, init=True, opts=None, user=None, identity=None)

Initialize git submodules

cwd
The path to the Git repository
init : True
Ensure that new submodules are initialized
opts : None
Any additional options to add to the command line
user : None
Run git as a user other than what the minion runs as
identity : None
A path to a private key to use over SSH

CLI Example:

salt '*' git.submodule /path/to/repo.git/sub/repo