One place for hosting & domains

      Reference

      SaltStack Command Line Reference


      Updated by Linode Contributed by Andy Stevens

      Use promo code DOCS10 for $10 credit on a new account.

      SaltStack is a powerful configuration management tool. The following is a quick-reference guide for Salt’s command line interface (CLI).

      salt

      Used to issue commands to minions in parallel. salt allows you to both control and query minions.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt --version
      -h, --helpDisplay Salt commands and help text.salt -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt -c /home/salt/conf test.ping
      -s, --staticOnly return data after all minions have returned.salt --static
      --asyncInstead of waiting for a job on a minion or minions, print the job ID and the job completion.salt '*' pkg.install apache2 --async
      --subsetExecute commands on a random subset of minions.salt '*' telegram.post_message message="Hello random 3!" --subset 3
      -v, --verbosePrint extra data, such as the job ID.salt 'minion1' user.add steve --verbose
      --hide-timeoutOnly print minions that can be reached.salt '*' test.ping --hide-timeout
      -b, --batch-sizeExecute on a batch or percentage of minions.salt '*' test.ping --batch-size 25%
      -a, --authUse an external authentication medium. You will be prompted for credentials. Options are auto, keystone, ldap, and pam. Can be used with -T.salt -a pam '*' status.meminfo
      -T, --make-tokenUsed with -a. Creates an authentication token in the active user’s home directory that has a default 12 hour expiration time. Token expiration time is set in the Salt master config file.salt -T -a pam '*' status.cpuinfo
      --returnUsed to select an alternative returner. Options are carbon, cassandra, couchbase, couchdb, elasticsearch, etcd, hipchat, local, local_cache, memcache, mongo, mysql, odbc, postgres, redis, sentry, slack, sms, smtp, sqlite3, syslog, and xmpp.salt '*' status.all_status --return mongo
      -d, --doc, --documentationReturn all available documentation for a module function, or all functions if one is not provided.salt 'minion3' service.available -d
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt 'minion2' state.apply -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt '*' test.ping --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt '*' test.ping --log-level all
      -E, --pcreTarget expression will be interpreted as a Perl Compatible Regular Expression (PCRE) rather than a shell glob.salt -E 'minion[0-9]' service.reload apache2
      -L, --listTarget expression will be interpreted as a comma-delimited list.salt -L 'minion1,minion2' service.show sshd
      -G, --grainTarget expression in the form of a glob expression matches a Salt grain. <grain value>:<glob expression>.salt -G 'os:Ubuntu' service.available mysql
      --grain-pcreTarget expression in the form of a Perl Compatible Regular Expression matches values returned by Salt grains on the minion.<grain value>:<regular expression>salt --grain-pcre 'os:Arch' service.restart apache2
      -I, --pillarUse pillar values instead of shell globs to identify targets.salt -I 'role:production' test.echo 'playback'
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml. Note: when using --out json you will probably want to also use --static.salt '*' test.version --out json --static

      salt-call

      Runs module functions on a minion instead of the master. It is used to run a standalone minion.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-call --version
      -h, --helpDisplay Salt commands and help text.salt-call -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-call -c /home/salt/conf test.ping
      -g, --grainsGet the information generated by the Salt grains.salt-call --grains
      -m, --module-dirsSelect an additional modules directory. You can provide this option multiple times for multiple directories.salt-call -m /home/salt/modules1 -m /home/salt/modules2
      -d, --doc, --documentationReturn all available documentation for module function, or all functions if one is not provided.salt-call system.get_system_time -d
      --masterChoose which master to use. The minion must be authenticated with the master. If the master is omitted, the first master in the minion config will be used.salt-call --master master1
      --returnUsed to select an alternative returner. Options are carbon, cassandra, couchbase, couchdb, elasticsearch, etcd, hipchat, local, local_cache, memcache, mongo, mysql, odbc, postgres, redis, sentry, slack, sms, smtp, sqlite3, syslog, and xmpp.salt-call --return mongo status.all_status
      --localRun Salt as if there was no master running.salt-call --local system.get_system_time
      --file-rootSet a directory as the base file directory.salt-call --file-root /home/salt
      --pillar-rootSet a directory as the base pillar directory.salt-call --file-root /home/salt/pillar
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-call -l all test.exception 'oh no!'
      --log-fileChange log file path. Defaults to /var/log/salt/minion.salt-call --logfile /home/salt/log/minion test.exception 'oh no!'
      --log-file-levelChange logfile log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-call --log-file-level all test.exception 'oh no!'
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml.salt-call test.version --out json

      salt-cloud

      Used to provision virtual machines on public clouds with Salt.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-cloud --version
      -h, --helpDisplay Salt commands and help text.salt-cloud -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-cloud -c /home/salt/conf
      -a, --actionPerform a cloud provider specific action. Requires an instance.salt-cloud -a reboot testlinode
      -f, --functionPerform a cloud provider specific function that does not apply to an instance. Requires a provider.salt-cloud -f clone my-linode-config linode_id=1234567 datacenter_id=2 plan_id=5
      -p, --profileChoose a profile from which to build cloud VMs.salt-cloud -p linode-1024 mynewlinode
      -m, --mapChoose a map file from which to create your VMs. If a VM exists it will be skipped.salt-cloud -m /path/to/map
      -H, --hardUsed when creating VMs with a map file. If set, will destroy all VMs not listed in the map file.salt-cloud -m /path/to/map -H
      -d, --destroyDestroy the named VMs. Can be used with -m to provide a map of VMs to destroy.salt-cloud -m /path/to/map -d
      -P, --parallelBuild VMs in parallel.salt-cloud -P -p linode-profile newlinode1 newlinode2
      -u, --update-boostrapUpdate salt-bootstrap.salt-cloud -u
      -y, --assume-yesAnswer yes to all questions.salt-cloud -y -d linode1 linode2
      -k, -keep-tmpDo not remove /tmp files.salt-cloud -k -m /path/to/map
      --show-deploy-argsInclude deployment arguments in the return data.salt-cloud --show-deploy-args -m /path/to/map
      --script-argsArguments to be passed to the bootstrap script when deploying.salt-cloud -m /path/to/map --script-args '-h'
      -Q, --queryQuery nodes running on configured cloud providers.salt-cloud -Q
      -F, --full-queryQuery VMs and print all available information. Can be used with -m to provide a map.salt-cloud -F
      -S, --select-queryQuery VMs and print selected information. Can be used with -m to provide a map.salt-cloud -S
      --list-providersDisplay a list of configured providers.salt-cloud --list-providers
      --list-profilesDisplay a list of configured profiles. Supply a cloud provider, such as linode, or pass all to view all configured profiles.salt-cloud --list-profiles linode
      --list-locationsDisplay a list of available locations. Supply a cloud provider, such as linode, or pass all to view all location for configured profiles.salt-cloud --list-locations linode
      --list-imagesDisplay a list of available images. Supply a cloud provider, such as linode, or pass all to view all images for configured profiles.salt-cloud --list-images linode
      --list-sizesDisplay a list of available sizes. Supply a cloud provider, such as linode, or pass all to view all sizes for configured profiles.salt-cloud --list-sizes linode
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml.salt-call test.version --out json

      salt-cp

      Used to copy files from the master to all Salt minions that match a specific target expression.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-cp --version
      -h, --helpDisplay Salt commands and help text.salt-cp -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-cp '*' -c /home/salt/conf /file/to/copy /destination
      -t, --timeoutThe amount of seconds to wait for replies from minions. The default is 5 seconds.salt-cp '*' -t 25 /file/to/copy /destination
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-cp '*' -l all /file/to/copy /destination
      --log-fileChange log file path. Defaults to /var/log/salt/master.salt-cp '*' --logfile /home/salt/log/minion /file/to/copy /destination
      --log-file-levelChange logfile log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-cp '*' --log-file-level all /file/to/copy /destination
      -E, --pcreTarget expression will be interpreted as a Perl Compatible Regular Expression (PCRE) rather than a shell glob.salt-cp -E 'minion[0-9]' /file/to/copy /destination
      -L, --listTarget expression will be interpreted as a comma-delimited list.salt -L 'minion1,minion2' /file/to/copy /destination
      -G, --grainTarget expression matches a Salt grain. <grain value>:<glob expression>.salt -G 'os:Ubuntu' /file/to/copy /destination
      --grain-pcreTarget expression in the form of a Perl Compatible Regular Expression matches values returned by Salt grains on the minion.<grain value>:<regular expression>salt-cp --grain-pcre 'os:Arch' /file/to/copy /destination
      -C, --chunkedUse chunked mode to copy files. Supports large files, recursive directories copying and compression.salt-cp -C /some/large/file /destination
      -n, --no-compressionDisable gzip in chunked mode.salt-cp -C -n /some/large/file /destination

      salt-key

      Used to manage the Salt server public keys.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-key --version
      -h, --helpDisplay Salt commands and help text.salt-key -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-key -c /home/salt/conf
      -u, --userSupply a user to run salt-key.salt-key --user steven
      -q, --quietSuppress outputsalt-key -q
      -y, --yesAnswer yes to all questions. Default is False.salt-key -y True
      --rotate-aes-keySetting to False prevents the key session from being refreshed when keys are deleted or rejected. Default is True.salt-key --rotate-aes-key False
      --log-fileChange log file path. Defaults to /var/log/salt/minion.salt-key --logfile /home/salt/log/minion -D
      --log-file-levelChange logfile log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-key --log-file-level all --accept '*'
      -l, --listList public keys. pre, un, and unaccepted will list unaccepted/unsigned keys. acc or accepted will list accepted/signed keys. rej or rejected will list rejected keys. all will list all keys.salt-key -l all
      -a, --acceptAccept a public key. Globs are supported.salt-key --accept 'minion*'
      -A, --accept-allAccept all pending keys.salt-key -A
      -r, --rejectReject a specific key. Globs are supported.salt-key -r 'minion*'
      -R, --reject-allReject all pending keys.salt-key -R
      --include-allInclude non-pending keys when accepting and rejecting.salt-key -r 'minion*' --include-all
      -p, --printPrint a public key.salt-key --print 'minion1'
      -d, --deleteDelete a public key. Globs are supported.salt-key -d 'minion*'
      -D, --delete-allDelete all public keys.salt-key --delete-all -y
      -f, --fingerPrint a key’s fingerprint.salt-key --finger 'minion1'
      -F, --finger-allPrint all keys’ fingerprints.salt-key --F
      --gen-keysSet a name to generate a key-pair.salt-key --gen-keys newminion
      --gen-keys-dirChoose where to save newly generated key-pairs. Only works with --gen-keys.salt-key --gen-keys newminion --gen-keys-dir /home/salt/keypairs
      --keysizeSet the keysize for a generated key. Must be a value of 2048 or higher. Only works with --gen-keys.salt-key --gen-keys newminion --keysize 4096
      --gen-signatureCreate a signature for the master’s public key named master_pubkey_signature. This requires a new-signing-keypair which can be created with the --auto-create option.salt-key --gen-signature --auto-create
      --privThe private-key file with which to create a signature.salt-key --priv key.pem
      --signature-pathThe file path for the new signature.salt-key --gen-signature --auto-create --signature-path /path/to/signature
      --pubThe public-key file with which to create a signature.salt-key --gen-signature key.pub
      --auto-createAuto-create a signing key-pair.salt-key --gen-signature --auto-create

      salt-master

      A daemon used to control Salt minions.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-master --version
      -h, --helpDisplay Salt commands and help text.salt-master -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-master -c /home/salt/conf
      -u, --userSupply a user to run salt-master.salt-master --user steven
      -d, --daemonRun salt-master as daemon.salt-master -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-master.pidsalt-master --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-master -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt-master --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-master --log-level all

      salt-minion

      A daemon that is controlled by a Salt master.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-minion --version
      -h, --helpDisplay Salt commands and help text.salt-minion -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-minion -c /home/salt/conf
      -u, --userSupply a user to run salt-minion.salt-minion --user steven
      -d, --daemonRun salt-minion as daemon.salt-minion -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-minion.pidsalt-minion --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-master -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/minionsalt-minion --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-minion --log-level all

      salt-run

      Runs a Salt runner on a Salt master.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-run --version
      -h, --helpDisplay Salt commands and help text.salt-run -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-run -c /home/salt/conf foo.bar
      -t, --timeoutThe amount of seconds to wait for replies from minions. The default is 5 seconds.salt-run -t 25 foo.bar
      -d, --doc, --documentationReturn all available documentation for a module or runner.salt-run foo.bar -d
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-run -l info foo.bar
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt-minion --log-file /home/salt/log foo.bar
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-minion --log-level all foo.bar

      salt-ssh

      Use SSH transport to execute salt routines.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-ssh --version
      -h, --helpDisplay Salt commands and help text.salt-ssh -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-ssh '*' -c /home/salt/conf test.ping
      -r, --raw, --raw-shellRun a raw shell command.salt-ssh '*' -r echo 'test'
      --rosterChoose which roster system to use. The default is the flat file roster.salt-ssh '192.168.0.0/16' --roster scan pkg.install apache2
      --roster-fileChange the roster file directory. The default is the same directory as the master config file.salt-ssh 'minion1' --roster-file /path/to/roster test.ping
      --refresh, --refresh-cacheUse to force refresh the target’s data in the master side cache before the auto refresh timeframe has been reached.salt-ssh 'minion1' --refresh-cache status.diskstats
      --max-procsThe number of minions to communicate with concurrently. In general, more connections mean faster communication. Default is 25.salt-ssh '*' --max-procs 50 test.ping
      -v, --verboseDisplay job ID.salt-ssh '*' -v test.ping
      -s, --staticReturn minion data as a grouping.salt-ssh '*' -s status.meminfo
      -w, --wipeRemove Salt files when the job is done.salt-ssh '*' -w state.apply
      -W. --rand-thin-dirDeploys to a random temp directory and cleans the directory when done.salt-ssh '*' -W state.apply
      --python2-binFile path to a python2 binary which has Salt installed.salt-ssh '*' --python2-bin /file/to/bin test.ping
      --python3-binFile path to a python3 binary which has Salt installed.salt-ssh '*' --python3-bin /file/to/bin test.ping
      --jidSupply a job ID instead of generating one.salt-ssh '*' -v --jid 00000000000000000000 test.ping
      --privSupply which SSH private key to use for authentication.salt-ssh '*' --priv /path/to/privkey status.netstats
      -i, --ignore-host-keysDisable StrictHostKeyChecking, which suppresses asking for connection approval.salt-ssh '*' -i pkg.install mysql-client
      --no-host-keysIgnores SSH host keys. Useful if an error persists with --ignore-host-keys.salt-ssh '*' -i --no-host-keys pkg.install cowsay
      --userSupply the user to authenticate with.salt-ssh '*' --user steven -r cowsay 'hello!'
      --passwdSupply the password to authenticate with.salt-ssh 'minion2' --passwd p455w0rd system.reboot
      --askpassRequest a password prompt.salt-ssh 'minion1' --askpass sys.doc
      --key-deployDeploy the authorized SSH key to all minions.salt-ssh '*' --key-deploy --passwd test.ping
      --sudoRun command with elevated privileges.salt-ssh '*' -r --sudo somecommand
      --scan-portsA comma-separated list of ports to scan in the scan roster.salt-ssh '192.168.0.0/16' --roster scan --scan-ports 22,23 test.ping
      --scan-timeoutTimeout for scan roster.salt-ssh '192.168.0.0/16' --roster scan --scan-timeout 100 test.ping
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-ssh -l info test.ping
      --log-fileChange the log file path. Defaults to /var/log/salt/sshsalt-ssh --log-file /home/salt/log test.ping
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-ssh --log-level all test.ping
      -E, --pcreTarget expression will be interpreted as a Perl Compatible Regular Expression (PCRE) rather than a shell glob.salt-ssh -E 'minion[0-9]' service.reload apache2
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml.salt-ssh '*' test.version --out json

      salt-syndic

      A minion set up on a master that allows for passing commands in from a higher master.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-syndic --version
      -h, --helpDisplay Salt commands and help text.salt-syndic -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-syndic -c /home/salt/conf
      -u, --userSupply a user to run salt-syndic.salt-syndic --user steven
      -d, --daemonRun salt-syndic as daemon.salt-syndic -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-syndic.pidsalt-syndic --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-syndic -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt-syndic --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-syndic --log-level all

      spm

      Salt Package Manager

      OptionDescriptionExample
      -y, --yesAnswer yes to all questions.spm remove -y apache
      -f, --forceForce spm to perform an action it would normally refuse to perform.
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.spm -l info install apache
      --log-fileChange the log file path. Defaults to /var/log/salt/spmspm --log-file /home/salt/log install mysql
      --log-file-levelChange the logging level of the log file. Same options as --log-levelspm --log-level all remove nginx
      CommandDescriptionExample
      update_repoUpdate locally configured repository metadata.spm update_repo
      installInstall a package by name from a configured SPM repository.spm install nginx
      removeRemove a package.spm remove apache
      infoGet an installed package’s information.spm info mysql
      filesList an installed package’s files.spm files mongodb
      localPerform a command on a local package, not a package in a repository or an installed package. Does not work with remove.spm local install /path/to/package
      buildBuild a package.spm build /path/to/package
      create_repoScan a directory for a valid SPM package and build an SPM-METADATA file in that directory.spm create_rep /path/to/package

      salt-api

      Used to start the Salt API

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-api --version
      -h, --helpDisplay Salt commands and help text.salt-api -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-api -c /home/salt/conf
      -u, --userSupply a user to run salt-api.salt-api --user steven
      -d, --daemonRun salt-api as daemon.salt-api -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-api.pidsalt-api --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-api -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/apisalt-api --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-api --log-level all

      More Information

      You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

      Join our Community

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link

      SaltStack Command Line Reference


      Updated by Linode Contributed by Andy Stevens

      Use promo code DOCS10 for $10 credit on a new account.

      SaltStack is a powerful configuration management tool. The following is a quick-reference guide for Salt’s command line interface (CLI).

      salt

      Used to issue commands to minions in parallel. salt allows you to both control and query minions.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt --version
      -h, --helpDisplay Salt commands and help text.salt -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt -c /home/salt/conf test.ping
      -s, --staticOnly return data after all minions have returned.salt --static
      --asyncInstead of waiting for a job on a minion or minions, print the job ID and the job completion.salt '*' pkg.install apache2 --async
      --subsetExecute commands on a random subset of minions.salt '*' telegram.post_message message="Hello random 3!" --subset 3
      -v, --verbosePrint extra data, such as the job ID.salt 'minion1' user.add steve --verbose
      --hide-timeoutOnly print minions that can be reached.salt '*' test.ping --hide-timeout
      -b, --batch-sizeExecute on a batch or percentage of minions.salt '*' test.ping --batch-size 25%
      -a, --authUse an external authentication medium. You will be prompted for credentials. Options are auto, keystone, ldap, and pam. Can be used with -T.salt -a pam '*' status.meminfo
      -T, --make-tokenUsed with -a. Creates an authentication token in the active user’s home directory that has a default 12 hour expiration time. Token expiration time is set in the Salt master config file.salt -T -a pam '*' status.cpuinfo
      --returnUsed to select an alternative returner. Options are carbon, cassandra, couchbase, couchdb, elasticsearch, etcd, hipchat, local, local_cache, memcache, mongo, mysql, odbc, postgres, redis, sentry, slack, sms, smtp, sqlite3, syslog, and xmpp.salt '*' status.all_status --return mongo
      -d, --doc, --documentationReturn all available documentation for a module function, or all functions if one is not provided.salt 'minion3' service.available -d
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt 'minion2' state.apply -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt '*' test.ping --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt '*' test.ping --log-level all
      -E, --pcreTarget expression will be interpreted as a Perl Compatible Regular Expression (PCRE) rather than a shell glob.salt -E 'minion[0-9]' service.reload apache2
      -L, --listTarget expression will be interpreted as a comma-delimited list.salt -L 'minion1,minion2' service.show sshd
      -G, --grainTarget expression in the form of a glob expression matches a Salt grain. <grain value>:<glob expression>.salt -G 'os:Ubuntu' service.available mysql
      --grain-pcreTarget expression in the form of a Perl Compatible Regular Expression matches values returned by Salt grains on the minion.<grain value>:<regular expression>salt --grain-pcre 'os:Arch' service.restart apache2
      -I, --pillarUse pillar values instead of shell globs to identify targets.salt -I 'role:production' test.echo 'playback'
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml. Note: when using --out json you will probably want to also use --static.salt '*' test.version --out json --static

      salt-call

      Runs module functions on a minion instead of the master. It is used to run a standalone minion.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-call --version
      -h, --helpDisplay Salt commands and help text.salt-call -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-call -c /home/salt/conf test.ping
      -g, --grainsGet the information generated by the Salt grains.salt-call --grains
      -m, --module-dirsSelect an additional modules directory. You can provide this option multiple times for multiple directories.salt-call -m /home/salt/modules1 -m /home/salt/modules2
      -d, --doc, --documentationReturn all available documentation for module function, or all functions if one is not provided.salt-call system.get_system_time -d
      --masterChoose which master to use. The minion must be authenticated with the master. If the master is omitted, the first master in the minion config will be used.salt-call --master master1
      --returnUsed to select an alternative returner. Options are carbon, cassandra, couchbase, couchdb, elasticsearch, etcd, hipchat, local, local_cache, memcache, mongo, mysql, odbc, postgres, redis, sentry, slack, sms, smtp, sqlite3, syslog, and xmpp.salt-call --return mongo status.all_status
      --localRun Salt as if there was no master running.salt-call --local system.get_system_time
      --file-rootSet a directory as the base file directory.salt-call --file-root /home/salt
      --pillar-rootSet a directory as the base pillar directory.salt-call --file-root /home/salt/pillar
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-call -l all test.exception 'oh no!'
      --log-fileChange log file path. Defaults to /var/log/salt/minion.salt-call --logfile /home/salt/log/minion test.exception 'oh no!'
      --log-file-levelChange logfile log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-call --log-file-level all test.exception 'oh no!'
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml.salt-call test.version --out json

      salt-cloud

      Used to provision virtual machines on public clouds with Salt.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-cloud --version
      -h, --helpDisplay Salt commands and help text.salt-cloud -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-cloud -c /home/salt/conf
      -a, --actionPerform a cloud provider specific action. Requires an instance.salt-cloud -a reboot testlinode
      -f, --functionPerform a cloud provider specific function that does not apply to an instance. Requires a provider.salt-cloud -f clone my-linode-config linode_id=1234567 datacenter_id=2 plan_id=5
      -p, --profileChoose a profile from which to build cloud VMs.salt-cloud -p linode-1024 mynewlinode
      -m, --mapChoose a map file from which to create your VMs. If a VM exists it will be skipped.salt-cloud -m /path/to/map
      -H, --hardUsed when creating VMs with a map file. If set, will destroy all VMs not listed in the map file.salt-cloud -m /path/to/map -H
      -d, --destroyDestroy the named VMs. Can be used with -m to provide a map of VMs to destroy.salt-cloud -m /path/to/map -d
      -P, --parallelBuild VMs in parallel.salt-cloud -P -p linode-profile newlinode1 newlinode2
      -u, --update-boostrapUpdate salt-bootstrap.salt-cloud -u
      -y, --assume-yesAnswer yes to all questions.salt-cloud -y -d linode1 linode2
      -k, -keep-tmpDo not remove /tmp files.salt-cloud -k -m /path/to/map
      --show-deploy-argsInclude deployment arguments in the return data.salt-cloud --show-deploy-args -m /path/to/map
      --script-argsArguments to be passed to the bootstrap script when deploying.salt-cloud -m /path/to/map --script-args '-h'
      -Q, --queryQuery nodes running on configured cloud providers.salt-cloud -Q
      -F, --full-queryQuery VMs and print all available information. Can be used with -m to provide a map.salt-cloud -F
      -S, --select-queryQuery VMs and print selected information. Can be used with -m to provide a map.salt-cloud -S
      --list-providersDisplay a list of configured providers.salt-cloud --list-providers
      --list-profilesDisplay a list of configured profiles. Supply a cloud provider, such as linode, or pass all to view all configured profiles.salt-cloud --list-profiles linode
      --list-locationsDisplay a list of available locations. Supply a cloud provider, such as linode, or pass all to view all location for configured profiles.salt-cloud --list-locations linode
      --list-imagesDisplay a list of available images. Supply a cloud provider, such as linode, or pass all to view all images for configured profiles.salt-cloud --list-images linode
      --list-sizesDisplay a list of available sizes. Supply a cloud provider, such as linode, or pass all to view all sizes for configured profiles.salt-cloud --list-sizes linode
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml.salt-call test.version --out json

      salt-cp

      Used to copy files from the master to all Salt minions that match a specific target expression.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-cp --version
      -h, --helpDisplay Salt commands and help text.salt-cp -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-cp '*' -c /home/salt/conf /file/to/copy /destination
      -t, --timeoutThe amount of seconds to wait for replies from minions. The default is 5 seconds.salt-cp '*' -t 25 /file/to/copy /destination
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-cp '*' -l all /file/to/copy /destination
      --log-fileChange log file path. Defaults to /var/log/salt/master.salt-cp '*' --logfile /home/salt/log/minion /file/to/copy /destination
      --log-file-levelChange logfile log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-cp '*' --log-file-level all /file/to/copy /destination
      -E, --pcreTarget expression will be interpreted as a Perl Compatible Regular Expression (PCRE) rather than a shell glob.salt-cp -E 'minion[0-9]' /file/to/copy /destination
      -L, --listTarget expression will be interpreted as a comma-delimited list.salt -L 'minion1,minion2' /file/to/copy /destination
      -G, --grainTarget expression matches a Salt grain. <grain value>:<glob expression>.salt -G 'os:Ubuntu' /file/to/copy /destination
      --grain-pcreTarget expression in the form of a Perl Compatible Regular Expression matches values returned by Salt grains on the minion.<grain value>:<regular expression>salt-cp --grain-pcre 'os:Arch' /file/to/copy /destination
      -C, --chunkedUse chunked mode to copy files. Supports large files, recursive directories copying and compression.salt-cp -C /some/large/file /destination
      -n, --no-compressionDisable gzip in chunked mode.salt-cp -C -n /some/large/file /destination

      salt-key

      Used to manage the Salt server public keys.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-key --version
      -h, --helpDisplay Salt commands and help text.salt-key -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-key -c /home/salt/conf
      -u, --userSupply a user to run salt-key.salt-key --user steven
      -q, --quietSuppress outputsalt-key -q
      -y, --yesAnswer yes to all questions. Default is False.salt-key -y True
      --rotate-aes-keySetting to False prevents the key session from being refreshed when keys are deleted or rejected. Default is True.salt-key --rotate-aes-key False
      --log-fileChange log file path. Defaults to /var/log/salt/minion.salt-key --logfile /home/salt/log/minion -D
      --log-file-levelChange logfile log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-key --log-file-level all --accept '*'
      -l, --listList public keys. pre, un, and unaccepted will list unaccepted/unsigned keys. acc or accepted will list accepted/signed keys. rej or rejected will list rejected keys. all will list all keys.salt-key -l all
      -a, --acceptAccept a public key. Globs are supported.salt-key --accept 'minion*'
      -A, --accept-allAccept all pending keys.salt-key -A
      -r, --rejectReject a specific key. Globs are supported.salt-key -r 'minion*'
      -R, --reject-allReject all pending keys.salt-key -R
      --include-allInclude non-pending keys when accepting and rejecting.salt-key -r 'minion*' --include-all
      -p, --printPrint a public key.salt-key --print 'minion1'
      -d, --deleteDelete a public key. Globs are supported.salt-key -d 'minion*'
      -D, --delete-allDelete all public keys.salt-key --delete-all -y
      -f, --fingerPrint a key’s fingerprint.salt-key --finger 'minion1'
      -F, --finger-allPrint all keys’ fingerprints.salt-key --F
      --gen-keysSet a name to generate a key-pair.salt-key --gen-keys newminion
      --gen-keys-dirChoose where to save newly generated key-pairs. Only works with --gen-keys.salt-key --gen-keys newminion --gen-keys-dir /home/salt/keypairs
      --keysizeSet the keysize for a generated key. Must be a value of 2048 or higher. Only works with --gen-keys.salt-key --gen-keys newminion --keysize 4096
      --gen-signatureCreate a signature for the master’s public key named master_pubkey_signature. This requires a new-signing-keypair which can be created with the --auto-create option.salt-key --gen-signature --auto-create
      --privThe private-key file with which to create a signature.salt-key --priv key.pem
      --signature-pathThe file path for the new signature.salt-key --gen-signature --auto-create --signature-path /path/to/signature
      --pubThe public-key file with which to create a signature.salt-key --gen-signature key.pub
      --auto-createAuto-create a signing key-pair.salt-key --gen-signature --auto-create

      salt-master

      A daemon used to control Salt minions.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-master --version
      -h, --helpDisplay Salt commands and help text.salt-master -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-master -c /home/salt/conf
      -u, --userSupply a user to run salt-master.salt-master --user steven
      -d, --daemonRun salt-master as daemon.salt-master -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-master.pidsalt-master --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-master -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt-master --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-master --log-level all

      salt-minion

      A daemon that is controlled by a Salt master.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-minion --version
      -h, --helpDisplay Salt commands and help text.salt-minion -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-minion -c /home/salt/conf
      -u, --userSupply a user to run salt-minion.salt-minion --user steven
      -d, --daemonRun salt-minion as daemon.salt-minion -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-minion.pidsalt-minion --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-master -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/minionsalt-minion --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-minion --log-level all

      salt-run

      Runs a Salt runner on a Salt master.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-run --version
      -h, --helpDisplay Salt commands and help text.salt-run -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-run -c /home/salt/conf foo.bar
      -t, --timeoutThe amount of seconds to wait for replies from minions. The default is 5 seconds.salt-run -t 25 foo.bar
      -d, --doc, --documentationReturn all available documentation for a module or runner.salt-run foo.bar -d
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-run -l info foo.bar
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt-minion --log-file /home/salt/log foo.bar
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-minion --log-level all foo.bar

      salt-ssh

      Use SSH transport to execute salt routines.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-ssh --version
      -h, --helpDisplay Salt commands and help text.salt-ssh -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-ssh '*' -c /home/salt/conf test.ping
      -r, --raw, --raw-shellRun a raw shell command.salt-ssh '*' -r echo 'test'
      --rosterChoose which roster system to use. The default is the flat file roster.salt-ssh '192.168.0.0/16' --roster scan pkg.install apache2
      --roster-fileChange the roster file directory. The default is the same directory as the master config file.salt-ssh 'minion1' --roster-file /path/to/roster test.ping
      --refresh, --refresh-cacheUse to force refresh the target’s data in the master side cache before the auto refresh timeframe has been reached.salt-ssh 'minion1' --refresh-cache status.diskstats
      --max-procsThe number of minions to communicate with concurrently. In general, more connections mean faster communication. Default is 25.salt-ssh '*' --max-procs 50 test.ping
      -v, --verboseDisplay job ID.salt-ssh '*' -v test.ping
      -s, --staticReturn minion data as a grouping.salt-ssh '*' -s status.meminfo
      -w, --wipeRemove Salt files when the job is done.salt-ssh '*' -w state.apply
      -W. --rand-thin-dirDeploys to a random temp directory and cleans the directory when done.salt-ssh '*' -W state.apply
      --python2-binFile path to a python2 binary which has Salt installed.salt-ssh '*' --python2-bin /file/to/bin test.ping
      --python3-binFile path to a python3 binary which has Salt installed.salt-ssh '*' --python3-bin /file/to/bin test.ping
      --jidSupply a job ID instead of generating one.salt-ssh '*' -v --jid 00000000000000000000 test.ping
      --privSupply which SSH private key to use for authentication.salt-ssh '*' --priv /path/to/privkey status.netstats
      -i, --ignore-host-keysDisable StrictHostKeyChecking, which suppresses asking for connection approval.salt-ssh '*' -i pkg.install mysql-client
      --no-host-keysIgnores SSH host keys. Useful if an error persists with --ignore-host-keys.salt-ssh '*' -i --no-host-keys pkg.install cowsay
      --userSupply the user to authenticate with.salt-ssh '*' --user steven -r cowsay 'hello!'
      --passwdSupply the password to authenticate with.salt-ssh 'minion2' --passwd p455w0rd system.reboot
      --askpassRequest a password prompt.salt-ssh 'minion1' --askpass sys.doc
      --key-deployDeploy the authorized SSH key to all minions.salt-ssh '*' --key-deploy --passwd test.ping
      --sudoRun command with elevated privileges.salt-ssh '*' -r --sudo somecommand
      --scan-portsA comma-separated list of ports to scan in the scan roster.salt-ssh '192.168.0.0/16' --roster scan --scan-ports 22,23 test.ping
      --scan-timeoutTimeout for scan roster.salt-ssh '192.168.0.0/16' --roster scan --scan-timeout 100 test.ping
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-ssh -l info test.ping
      --log-fileChange the log file path. Defaults to /var/log/salt/sshsalt-ssh --log-file /home/salt/log test.ping
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-ssh --log-level all test.ping
      -E, --pcreTarget expression will be interpreted as a Perl Compatible Regular Expression (PCRE) rather than a shell glob.salt-ssh -E 'minion[0-9]' service.reload apache2
      --outChoose an alternative outputter to display returned data. Available outputters are: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml.salt-ssh '*' test.version --out json

      salt-syndic

      A minion set up on a master that allows for passing commands in from a higher master.

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-syndic --version
      -h, --helpDisplay Salt commands and help text.salt-syndic -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-syndic -c /home/salt/conf
      -u, --userSupply a user to run salt-syndic.salt-syndic --user steven
      -d, --daemonRun salt-syndic as daemon.salt-syndic -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-syndic.pidsalt-syndic --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-syndic -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/mastersalt-syndic --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-syndic --log-level all

      spm

      Salt Package Manager

      OptionDescriptionExample
      -y, --yesAnswer yes to all questions.spm remove -y apache
      -f, --forceForce spm to perform an action it would normally refuse to perform.
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.spm -l info install apache
      --log-fileChange the log file path. Defaults to /var/log/salt/spmspm --log-file /home/salt/log install mysql
      --log-file-levelChange the logging level of the log file. Same options as --log-levelspm --log-level all remove nginx
      CommandDescriptionExample
      update_repoUpdate locally configured repository metadata.spm update_repo
      installInstall a package by name from a configured SPM repository.spm install nginx
      removeRemove a package.spm remove apache
      infoGet an installed package’s information.spm info mysql
      filesList an installed package’s files.spm files mongodb
      localPerform a command on a local package, not a package in a repository or an installed package. Does not work with remove.spm local install /path/to/package
      buildBuild a package.spm build /path/to/package
      create_repoScan a directory for a valid SPM package and build an SPM-METADATA file in that directory.spm create_rep /path/to/package

      salt-api

      Used to start the Salt API

      OptionDescriptionExample
      --versionGet the current version of Salt.salt-api --version
      -h, --helpDisplay Salt commands and help text.salt-api -h
      -c, --config-dirChange the Salt configuration directory. The default is /etc/salt.salt-api -c /home/salt/conf
      -u, --userSupply a user to run salt-api.salt-api --user steven
      -d, --daemonRun salt-api as daemon.salt-api -d
      --pid-fileSpecify the file path of the pidfile. Default is /var/run/salt-api.pidsalt-api --pid-file /path/to/new/pid
      -l, --log-levelChange console log level. Defaults to warning. Available options are all, garbage, trace, debug, info, warning, error, and quiet.salt-api -l info
      --log-fileChange the log file path. Defaults to /var/log/salt/apisalt-api --log-file /home/salt/log
      --log-file-levelChange the logging level of the log file. Same options as --log-levelsalt-api --log-level all

      More Information

      You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

      Join our Community

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link

      How To Use Git: A Reference Guide


      Git Cheat Sheet

      Introduction

      Teams of developers and open-source software maintainers typically manage their projects through Git, a distributed version control system that supports collaboration.

      This cheat sheet-style guide provides a quick reference to commands that are useful for working and collaborating in a Git repository. To install and configure Git, be sure to read “How To Contribute to Open Source: Getting Started with Git.”

      How to Use This Guide:

      • This guide is in cheat sheet format with self-contained command-line snippets.
      • Jump to any section that is relevant to the task you are trying to complete.
      • When you see highlighted text in this guide’s commands, keep in mind that this text should refer to the commits and files in your own repository.

      Set Up and Initialization

      Check your Git version with the following command, which will also confirm that Git is installed.

      You can initialize your current working directory as a Git repository with init.

      To copy an existing Git repository hosted remotely, you’ll use git clone with the repo’s URL or server location (in the latter case you will use ssh).

      • git clone https://www.github.com/username/repo-name

      Show your current Git directory’s remote repository.

      For a more verbose output, use the -v flag.

      Add the Git upstream, which can be a URL or can be hosted on a server (in the latter case, connect with ssh).

      • git remote add upstream https://www.github.com/username/repo-name

      Staging

      When you’ve modified a file and have marked it to go in your next commit, it is considered to be a staged file.

      Check the status of your Git repository, including files added that are not staged, and files that are staged.

      To stage modified files, use the add command, which you can run multiple times before a commit. If you make subsequent changes that you want included in the next commit, you must run add again.

      You can specify the specific file with add.

      With . you can add all files in the current directory including files that begin with a ..

      You can remove a file from staging while retaining changes within your working directory with reset.

      Committing

      Once you have staged your updates, you are ready to commit them, which will record changes you have made to the repository.

      To commit staged files, you’ll run the commit command with your meaningful commit message so that you can track commits.

      • git commit -m "Commit message"

      You can condense staging all tracked files with committing them in one step.

      • git commit -am "Commit message"

      If you need to modify your commit message, you can do so with the --amend flag.

      • git commit --amend -m "New commit message"

      Branches

      A branch in Git is a movable pointer to one of the commits in the repository, it allows you to isolate work and manage feature development and integrations. You can learn more about branches by reading the Git documentation.

      List all current branches with the branch command. An asterisk (*) will appear next to your currently active branch.

      Create a new branch. You will remain on your currently active branch until you switch to the new one.

      Switch to any existing branch and check it out into your current working directory.

      • git checkout another-branch

      You can consolidate the creation and checkout of a new branch by using the -b flag.

      • git checkout -b new-branch

      Rename your branch name.

      • git branch -m current-branch-name new-branch-name

      Merge the specified branch’s history into the one you’re currently working in.

      Abort the merge, in case there are conflicts.

      You can also select a particular commit to merge with cherry-pick with the string that references the specific commit.

      When you have merged a branch and no longer need the branch, you can delete it.

      • git branch -d branch-name

      If you have not merged a branch to master, but are sure you want to delete it, you can force delete a branch.

      • git branch -D branch-name

      Collaborate and Update

      To download changes from another repository, such as the remote upstream, you’ll use fetch.

      Merge the fetched commits.

      • git merge upstream/master

      Push or transmit your local branch commits to the remote repository branch.

      Fetch and merge any commits from the tracking remote branch.

      Inspecting

      Display the commit history for the currently active branch.

      Show the commits that changed a particular file. This follows the file regardless of file renaming.

      • git log --follow my_script.py

      Show the commits that are on one branch and not on the other. This will show commits on a-branch that are not on b-branch.

      • git log a-branch..b-branch

      Look at reference logs (reflog) to see when the tips of branches and other references were last updated within the repository.

      Show any object in Git via its commit string or hash in a more human-readable format.

      Show Changes

      The git diff command shows changes between commits, branches, and more. You can read more fully about it through the Git documentation.

      Compare modified files that are on the staging area.

      Display the diff of what is in a-branch but is not in b-branch.

      • git diff a-branch..b-branch

      Show the diff between two specific commits.

      • git diff 61ce3e6..e221d9c

      Stashing

      Sometimes you’ll find that you made changes to some code, but before you finish you have to begin working on something else. You’re not quite ready to commit the changes you have made so far, but you don’t want to lose your work. The git stash command will allow you to save your local modifications and revert back to the working directory that is in line with the most recent HEAD commit.

      Stash your current work.

      See what you currently have stashed.

      Your stashes will be named stash@{0}, stash@{1}, and so on.

      Show information about a particular stash.

      To bring the files in a current stash out of the stash while still retaining the stash, use apply.

      • git stash apply stash@{0}

      If you want to bring files out of a stash, and no longer need the stash, use pop.

      If you no longer need the files saved in a particular stash, you can drop the stash.

      If you have multiple stashes saved and no longer need to use any of them, you can use clear to remove them.

      Ignoring Files

      If you want to keep files in your local Git directory, but do not want to commit them to the project, you can add these files to your .gitignore file so that they do not cause conflicts.

      Use a text editor such as nano to add files to the .gitignore file.

      To see examples of .gitignore files, you can look at GitHub’s .gitignore template repo.

      Rebasing

      A rebase allows us to move branches around by changing the commit that they are based on. With rebasing, you can squash or reword commits.

      You can start a rebase by either calling the number of commits you have made that you want to rebase (5 in the case below).

      Alternatively, you can rebase based on a particular commit string or hash.

      Once you have squashed or reworded commits, you can complete the rebase of your branch on top of the latest version of the project’s upstream code.

      • git rebase upstream/master

      To learn more about rebasing and updating, you can read How To Rebase and Update a Pull Request, which is also applicable to any type of commit.

      Resetting

      Sometimes, including after a rebase, you need to reset your working tree. You can reset to a particular commit, and delete all changes, with the following command.

      To force push your last known non-conflicting commit to the origin repository, you’ll need to use --force.

      Warning: Force pushing to master is often frowned upon unless there is a really important reason for doing it. Use sparingly when working on your own repositories, and work to avoid this when you’re collaborating.

      • git push --force origin master

      To remove local untracked files and subdirectories from the Git directory for a clean working branch, you can use git clean.

      If you need to modify your local repository so that it looks like the current upstream master (that is, there are too many conflicts), you can perform a hard reset.

      Note: Performing this command will make your local repository look exactly like the upstream. Any commits you have made but that were not pulled into the upstream will be destroyed.

      • git reset --hard upstream/master

      Conclusion

      This guide covers some of the more common Git commands you may use when managing repositories and collaborating on software.

      You can learn more about open-source software and collaboration in our Introduction to Open Source tutorial series:

      There are many more commands and variations that you may find useful as part of your work with Git. To learn more about all of your available options, you can run:

      To receive useful information. You can also read more about Git and look at Git’s documentation from the official Git website.



      Source link