Skip to content

feat: add --pull-before-push option - #90

Open
oschrenk wants to merge 1 commit into
croissong:mainfrom
oschrenk:feat/pull-before-push
Open

oschrenk wants to merge 1 commit into
croissong:mainfrom
oschrenk:feat/pull-before-push

Conversation

@oschrenk

@oschrenk oschrenk commented Nov 7, 2026 •

Copy link
Copy Markdown

Closes #78.

Ports the -R (PULL_BEFORE_PUSH) option of the original gitwatch.sh. The flag name follows that option, not the --pull-rebase name from the issue.

With --pull-before-push and a --remote, gitwatch fetches the current branch from the remote after each commit and before the push. It then fast-forwards, or rebases the local commits on top of the remote ones. This keeps the push working when the remote has moved ahead, such as when you edit the same repository on two machines.

Usage

gitwatch watch --remote origin --pull-before-push .

Or in gitwatch.yaml:

remote: origin
pull_before_push: true

The option requires a remote.

Known limitations

  • The branch must exist on the remote. Push a new branch once before you use this option.
  • libgit2 has no autostash, so this PR does not do the autostash that pull --rebase before push? #78 asks for. In practice gitwatch commits all changes before the pull. If a tracked file that --ignore-regex excludes has local edits, the rebase fails with unstaged changes exist in workdir.
  • After a failed pull, gitwatch pushes the commit with the next change. A failed push already works like this.

Port gitwatch's PULL_BEFORE_PUSH (-R): after committing and before
pushing, fetch the current branch from the remote and rebase the local
commits on top of it, so a remote that has moved ahead no longer breaks
the push.

Implemented with libgit2 instead of shelling out to git: fetch via the
existing GitAuthenticator, then merge analysis deciding between
up-to-date, fast-forward and rebase. A conflicting rebase is aborted, so
the repository is never left in a rebasing state; the error propagates
into the regular retry loop.

Requires a remote, which is validated in AppConfig. Configurable via
--pull-before-push or pull_before_push in gitwatch.yaml.
@oschrenk oschrenk changed the title feat(repo): add --pull-before-push option feat: add --pull-before-push option Nov 7, 2026
@croissong

Copy link
Copy Markdown
Owner

@oschrenk Sorry I've been inactive, thanks for the PRs! I will take a look at them this weekend, I promise :)
I can also add you as maintainer if you'd like.

@oschrenk

oschrenk commented Nov 19, 2026 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pull --rebase before push?

2 participants