Searched for tag sync and found 2 results in 0.6 ms

Using rsync to keep two directories in sync

I have two directories with (mostly) the same content that I want to keep in sync. Specifically I want to make sure that the newest version of each file is synced to the other directory. This allows me to update a file on either side, and that version will propagate to the other. You can do this with a bi-directional rsync command:

rsync --update -av /dir/a/ /dir/b/
rsync --update -av /dir/b/ /dir/a/

Using --update tells rsync to skip files on the receiving side that are newer. If you sync a -> b and then b -> a you end up with both locations having the newest copy of each file.

Tags:
Leave A Reply

Git: Keep two branches in sync

I have a Git repository with a primary branch that I maintain actively. I also have a separate feature branch that I'd like to keep in sync with the main branch, and alert if there are any conflicts immediately. Using Git hooks you can script automatically pulling each new commit from the primary branch to the feature branch.

Create a .git/hooks/post-commit file and put these contents in it:

#!/bin/sh

SRC="main"
DST="feature"

branch=$(git branch --show-current)

if [ "$branch" = "$SRC" ]; then
    commit=$(git rev-parse HEAD)

    git checkout $DST &&
    git cherry-pick "$commit" &&
    git checkout main
fi

If there are conflicts, Git errors out immediately and leaves you on the feature branch to manually resolve the conflict.

Tags:
Leave A Reply