Skip to content
\n

The above code works sucessfully to pull the changes, but I only want to pull only if there's any update in the remote repo. Not sure how to achieve this.

\n

Basically I want git diff <local branch> <remote>/<remote branch> and want to compare before I pull. Do I have to do Repo(repo_path).remotes.origin.fetch() as well ?

\n

Thank you.
\nHave a great day!

","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"

nevermind! I did it.
\nHere's what I did:

\n
Repo(repo_path).remotes.origin.fetch()\ndiff = str(Repo(repo_path).git.diff('origin/master')).splitlines()\nif len(diff) != 0:\n    Repo(repo_path).remote().pull(branch)\n
\n

It works!
\nThanks for replying
\nHave a great day ahead :-)

","upvoteCount":3,"url":"https://github.com/gitpython-developers/GitPython/discussions/1148#discussioncomment-408798"}}}

git diff <local branch> <remote>/<remote branch> possible using gitpython ? #1148

Answered by hcheruku
hcheruku asked this question in Q&A
Discussion options

You must be logged in to vote

nevermind! I did it.
Here's what I did:

Repo(repo_path).remotes.origin.fetch()
diff = str(Repo(repo_path).git.diff('origin/master')).splitlines()
if len(diff) != 0:
    Repo(repo_path).remote().pull(branch)

It works!
Thanks for replying
Have a great day ahead :-)

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Byron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #989 on February 26, 2021 11:18.