Skip to content

Git Operations

ensure_git.sh

Convenience functions for working with Git repositories

Functions

ensure_git_repository_up_to_date

Ensure that a Git repository is checked out at the latest version specific remote tag, branch or commit. Also updates submodules. Currently the remote needs to be named "origin" (which is the default).

Examples

  • Clone dotfiles from a remote repository and checkout the latest version of the master branch:
    ensure_git_repository_up_to_date --ref=master \
      https://codeberg.org/unixchad/dotfiles.git \
      $HOME/.local/share/dotfiles
    [ $ENSURE_CHANGED -eq 0 ] || stow -t ~ $HOME/.local/share/dotfiles --adopt
    
Arguments
  • --ref={ref}:

    The Git reference (tag, branch or commit) to checkout. Defaults to the currently checked out branch or the default branch if the repo isn't cloned yet.

  • --force:

    If there are local changes, do a hard reset. WARNING: this can and will delete any uncommitted/unpushed local changes!

  • {remote-url}:

    Repository URL on the origin remote. Ignored if the repository is already cloned locally.

  • {local-path}:

    Path to the local Git repository.