1

I have been working on a PowerShell script that goes through all my git directories, with a goal of if there any changes to the remote, perform a pull and then compile the source.

I have a working script but when I did a manual pull I found that I was not pulling the information.

One of the repositories I pull from is the boost repository (https://github.com/boostorg/boost.git). This project has a main project and number of sub projects.

I am running this through PowerShell on Windows. I also have posh-git installed.

The first thing the script does is a cd into the git directory (... Boost\boost-git). After that I perform the following:

Write-Host "git status"
git status

Write-Host "git branch"
git branch

$RemoteBranch = git remote
Write-Host "Remote       : '$RemoteBranch'"

if ($RemoteBranch -ne $null) {
    $RemoteURL = git remote get-url --all $RemoteBranch
    Write-Host "Remote URL   : '$RemoteURL'"
}

Write-Host "`ngit branch | ForEach-Object { Get-GitStatus $_. }"
git branch | ForEach-Object {
    $status = Get-GitStatus $_.
    $status
    $BehindBy += $status.BehindBy
}

Write-Host "`ngit diff-index --quiet HEAD"
$GitHead = git diff-index --quiet HEAD
$GitHead
if ($GitHead -ne "") {
    Write-Host "`nNo Changes"
} else {
    Write-Host "`nChanges"
    $GitHead
}

Write-Host "`nBehindBy Sum $BehindBy"

if ($BehindBy -gt 0) {
    git fetch --all
}

While the script runs, I am not pulling the repository when the remote has been updated.

Any help would be greatly appreciated or let me know which commands I should be parsing.

6
  • You say that it didn't pull but nowhere, you pulled. You only fetch... Do a pull instead or do also a rebase or merge. Commented Jan 9, 2018 at 23:06
  • Hi Philippe, I originally had a pull instead of a fetch. Either way I don't think I am using the correct git commands to determine when the remote has been updated. Commented Jan 10, 2018 at 22:30
  • I am still looking for some help understanding what the correct git command(s) are so I can check if the remote needs to be pulled. Any help? Commented Jan 17, 2018 at 15:15
  • Remove the last test and fetch all the time. Why do you care if you are behind or not. The problem should come from here because you should fetch before knowing if you are behind. And also perhaps you should try to debug your script yourself. And also put output of the script in your question to help others, no!?! Commented Jan 17, 2018 at 18:51
  • Hi Philippe, The issue is not the pull or the fetch. I can write a script that always does that. What I am trying to do is know when I should do a pull so I can then perform other tasks. I have been debugging my script. I also use another script that just pulls no matter what, which is how I noticed this script is not doing what I expected. I have tried a number of different git commands but I am still at a loss to determine which git command is the correct one to determine when the remote has changed. Commented Jan 19, 2018 at 22:50

1 Answer 1

1

After more searching I found the answer how to do this. It can be found at Check if pull needed in Git

Nice write up on different bash strategies that can be adapted to powershell, as the authors explain each of the commands.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.