LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-sync

Hard-reset a branch to match its remote, cleaning untracked files

TLDR

Sync current branch with its upstream
$ git sync
copy
Sync with a specific remote and branch
$ git sync [origin] [main]
copy
Sync but keep untracked/ignored files
$ git sync --soft
copy
Sync without a confirmation prompt
$ git sync --force
copy

SYNOPSIS

git sync [remote branch] [-s | --soft] [-f | --force]

DESCRIPTION

git sync is a git-extras command that fetches the given (or upstream-tracked) remote branch and then runs `git reset --hard` to make the current branch match it exactly. Unless `-s`/`--soft` is given, it also runs `git clean -d -f -x` afterward, deleting every untracked and ignored file in the working tree.It asks for confirmation before running unless `-f`/`--force` is passed.

PARAMETERS

REMOTE BRANCH

Remote and branch to sync with; defaults to the current branch's configured upstream.
-s, --soft
Skip `git clean -d -f -x` after resetting, keeping untracked and ignored files.
-f, --force
Skip the confirmation prompt.
-h, --help
Display usage information.

INSTALL

sudo zypper install git-sync
copy
brew install git-sync
copy
nix profile install nixpkgs#git-sync
copy

CAVEATS

This is destructive: local commits not on the remote, uncommitted changes, and (without `-s`) untracked/ignored files are all discarded. It is not a fetch-and-rebase or fetch-and-merge; unlike `git pull`, divergent local work is thrown away rather than integrated.

SEE ALSO

RESOURCES

Copied to clipboard
Kai