Rsync not considering timestamps while syncronising git repos after permissions changed

I had a git repo on machine A.

I did an rsync from machine A to machine B using the flags

rsync -zvaP  /media/shihab/development shihab@remote:/media/shihab/OSDisk/development

Later I did some changes in machine B and did an rsync from machine B to machine A using the same flags:

rsync -zvaP shihab@remote:/media/shihab/OSDisk/development /media/shihab/development 

During the sync, I realized that even the files without modifications were synced. Turns out both times of the sync operation, the file owner and permissions were changed. Doing a git status in the repo would tell me that user permissions were changed.

To rectify this, I made changes to the git config global and local by adding core.filemode=false as:

git config --global core.fileMode false
git config --local core.fileMode false

Furthermore, I added the flags, rsync -zvaP --no-perms --no-owner --no-group to my sync to ask rsync to forget about writing the permissions. For example:

rsync -zvaP --no-perms --no-owner --no-group /media/shihab/development shihab@remote:/media/shihab/OSDisk/development

However, despite that change, when I rsync from machine B to machine A, it is overwriting a file with a newer timestamp with that on machine B with an older time-stamp. I can see it if I do a --dry-run -i. The file looks like this on machine B:

-rwxrwxrwx 1 shihab shihab 655 Nov 16 2021 install-i3wm.sh*

While on machine A it looks like:

-rwxrwxrwx 1 shihab shihab 681 Jun 22 11:06 install-i3wm.sh*

when I do an rsync from Machine B to machine A as follows:

rsync -zvaP --dry-run -i -t --no-perms --no-owner --no-group shihab@remote:/media/shihab/OSDisk/development /media/shihab/development

I get:

f+++++++++ install-i3wm.sh

What am I doing wrong?

Asked By: Shihab Khan

||

You say that rsync "is overwriting a file with a newer timestamp with that on machine B with an older time-stamp".

The two files are different so the destination will be updated to match the source. That’s what rsync does.

If you want rsync only to update files when the source is newer than the destination you needed to tell it that’s the modified behaviour that you want. In this case include -u (--update).

Answered By: roaima