0

I'm checking to see if a remote needs a pull using a method from Check if pull needed in Git

I'm using the approach that looks like this in a Python script:

 % git fetch origin

 # See if there are any incoming changes
 % git log HEAD..origin/master --oneline

I don't want to leave side effects, so I'm thinking that I should clear the fetch away. How do I do that?

Ray Salemi
  • 5,247
  • 4
  • 30
  • 63
  • 3
    There is generally no reason to do that. If you really do want to "undo" the effect of the fetch on any fetched references, you will need to save all the old values and then restore them, or use a fetch form that doesn't update them in the first place. The former introduces races if there are other `git fetch`es that might run in parallel: you might undo something someone really wanted done! The latter races with anyone using `FETCH_HEAD`. So there's no perfect solution here. – torek Jan 23 '18 at 19:14

1 Answers1

1

You can use git remote show . It will show your local branches and show the ones that are out of date:

Local refs configured for 'git push':
  gh-pages pushes to gh-pages (up to date)
  master   pushes to master   (local out of date)
  staging  pushes to staging  (up to date)

In the example above it shows that branch master is out of date, but it didn't fetch the branch, so your local repository stays untouched.

Alberto Pires
  • 319
  • 1
  • 5
  • 10