0

I am attempting to create a bash script that clones a repository off of a Github account and places it on an NFS volume on a Raspberry Pi cluster. It will be run via cron job at midnight daily. Of course, I don't want to pull from this repo more than I need to. Cloning is done easily enough in the bash script, but how would I check for differences between the current copy of the directory on my machine and the current revision of the repository? I see guides on how to do this with branching and the like, but I don't want to make any changes to the source. I just want to check the differences and re-run git clone --depth=1 https://github.org/somerepo/something to the NFS directory if there have been changes.

If I'm misunderstanding how cloning works, please let me know.

nerdenator
  • 1,265
  • 2
  • 18
  • 35
  • 3
    You can use `git fetch --dry-run` to see what, if anything, would be pulled, See a friendly manual near you. `git clone` is used for downloading the repository when you have none. – msw Sep 22 '15 at 02:54
  • 1
    Just use `git pull`, it won't download anything if there are no changes. – ryanpcmcquen Sep 22 '15 at 02:54
  • `git fetch --all` and then `git branch -av` will indicate when ahead/behind meaning there is a difference. There is usually no reason to use --dry-run when fetching and there is no way to ask git to compare one thing with another that isn't locally available. If in doubt perform a local file backup, or copy the entire toplevel directory to another place /tmp/foo/ and test commands there. `git pull` will modify the working tree if it needs to. `pull` always does an implicit `fetch` first. – Darryl Miles Sep 22 '15 at 03:06

2 Answers2

0

So as I understand it, you want to peek at the remote, but not pull anything down yet?

git ls-remote --heads origin

will show the remote heads on origin. You can compare each of these to your remote tracking branches and if the commits differ (or you don't have a remote tracking branch for the remote branch), then fetching would most likely pull in the new commits.

David Neiss
  • 8,161
  • 2
  • 20
  • 21
0

If bare repo is suit you then create local repo with following command: git clone --mirror.

For update do git remote update in the folder. This command downloads only a difference between local and remote repos.

axon
  • 4,081
  • 1
  • 12
  • 14