3

I have a script which emails me a reminder if I've forgotten to commit or push some code on each of my 40+ repositories.

With 2 of my projects, I have followed the answers in these posts, where I have set-up "git-push" to push to multiple repositories:

pull/push from multiple remote locations

git push to multiple repositories simultaneously

So I have a .git/config file with:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "origin"]
    url = https://www.example.com/git/project/
    url = git@github.com:username/project.git
[remote "example"]
    url = https://www.example.com/git/project/
    fetch = +refs/heads/*:refs/remotes/example/*
[remote "github"]
    url = git@github.com:username/project.git
    fetch = +refs/heads/*:refs/remotes/github/*

This works well when it comes to doing a git push/pull.

With the script I have used:

git status --short

But this only shows un-commited changes... even without the "--short" flag, it does not show what normally appears with only 1 remote:

Your branch is ahead of 'origin/master' by 1 commit.

Trying to run any of the following "diff" commands also doesn't seem to work... well it does on the first time, but it seems to remember the remote files at the date/time when it was setup, so as you make more changes it compares them against that version in history:

git diff --name-status "origin";
git diff --name-status "origin/master";
git diff --name-status "example/master";
git diff --name-status "github/master";

Any thoughts? I am fairly new to Git.

Community
  • 1
  • 1
Craig Francis
  • 1,855
  • 3
  • 22
  • 35
  • What do you mean with »as you make more changes it compares them against that version of history«? Of course it will compare your currently committed version. And since you push to your remotes, there won't be any diff to show (remotes and HEAD point to the same commit), unless you have uncommitted changes. – knittl Jul 27 '12 at 09:10
  • 1
    Are you sure you didn't just forget to run `git fetch --all` from time to time? – fork0 Jul 27 '12 at 09:26
  • @knittl, @fork0 I have done the `git fetch --all` (no files pulled back)... it's when I run the `git diff --name-status "origin"` it still says that I have modified files even though in this case I have committed and pushed all changes... it seems to be saying these files are different to the files as they were when I first configured having these multiple remotes (basically these files are modified in comparison to what the remote servers had last month). – Craig Francis Jul 27 '12 at 10:41
  • @CraigFrancis: are the modifications you see local (_uncommitted_) modifications? That's expected, if you call `diff` with a single commit only: it will compare your working tree with the commit. To compare the last commit with a remote commit, run `git diff HEAD origin/master` – knittl Jul 27 '12 at 10:57
  • @knittl, everything has been committed and pushed, so no... and running `git diff HEAD origin/master` shows that I have thousands of differences, all describing changes I have already committed and pushed to the remote repositories... its as though its comparison is being made against an old version, the version it got before setting up these multiple repositories... thanks for checking though. – Craig Francis Jul 27 '12 at 11:16

1 Answers1

0

I believe this method is possibly a bit buggy, as it seems to remember a commit ref for each remote, but this does not get updated when doing a push/pull... so when checking via a diff, its always going to look at the old commit ref for a comparison.

While its not a solution to this setup, I have gone back to a single remote setup, but edited it so that it has 2 urls... so while the pull only happens from one remote, when I push, it goes to two:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://www.example.com/git/project/
    url = git@github.com:username/project.git

Note: This only works for now, as I'm the only committer.

Craig Francis
  • 1,855
  • 3
  • 22
  • 35