0

Is it possible to know whether new commits have occured on remote git server using git commands inside bash script? I need it for automatic getting changes from remote host only when they exist.

Bouke
  • 1,531
  • 1
  • 12
  • 21
Hermann
  • 247
  • 2
  • 18
  • If you have new commits from upstream, do you always want to pull them? If you do, you don't need to check anything. – everton Aug 31 '18 at 12:50
  • After pulling I plan to start project build but I don't want ot start it when there was no changes in code – Hermann Aug 31 '18 at 12:52
  • https://stackoverflow.com/questions/6006759/git-bash-how-to-check-if-theres-a-new-commit-available – phd Aug 31 '18 at 14:38

1 Answers1

2

Just execute a git fetch. When there are no changes, nothing will happen, and when there are changes, they will be retrieved from the remote server. You could also use a git pull, in case changes are automatically merged.

Some more information: https://www.git-tower.com/learn/git/faq/difference-between-git-fetch-git-pull

Bouke
  • 1,531
  • 1
  • 12
  • 21
  • It was my fault. I thought that git fetch only writes data to local git database but fight now I rechecked it and found out that it also returns text but only one time per change in remote server. If I call it second time it returns nothing – Hermann Aug 31 '18 at 13:04
  • @Hermann - I'm not sure if I'm following your comment. If you call `fetch` a second time, it returns nothing because there are no changes, since your local was just updated by the first call. – Mark Adelsberger Aug 31 '18 at 13:25