You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
git diff <local branch> <remote>/<remote branch> possible using gitpython ? #989
I looked into remote and diff part of the documentation & API but couldn't find a way to achieve git diff between local and remote repo.
Here's what I am trying to achieve:
check if local repo matches remote repo, and ONLY if remote repo has any/some updates then pull and update the local repo.
from git import Repo
Repo(local_repo_path).remote().pull(branch)
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.
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 ?
if I understand you correctly, you would like to diff a local state against the state in a remote repository, without actually fetching data to local. This is not possible with git.
However, removing that constraint, you can always fetch the data first, then diff or compare the commit hash the local branch and remote branch points to.
It would certainly help to understand the problem you are trying to solve. In the mean time, I will close this issue, feel free to keep posting in the comments.
Thank you so much for replying.
Sorry, I didn't mean to diff without fetch. haha sorry for the confusion. I know I cannot diff without fetch. I have no problem git fetching using gitpython. Repo(repo_path).remotes.origin.fetch() works fine.
Just want to know how to do git diff local remote using gitpython.
Activity
Byron commentedon Feb 25, 2020
Hi @hcheruku ,
if I understand you correctly, you would like to diff a local state against the state in a remote repository, without actually fetching data to local. This is not possible with git.
However, removing that constraint, you can always fetch the data first, then diff or compare the commit hash the local branch and remote branch points to.
It would certainly help to understand the problem you are trying to solve. In the mean time, I will close this issue, feel free to keep posting in the comments.
hcheruku commentedon Feb 25, 2020
Hi Byron,
Thank you so much for replying.
Sorry, I didn't mean to diff without fetch. haha sorry for the confusion. I know I cannot diff without fetch. I have no problem git fetching using gitpython.
Repo(repo_path).remotes.origin.fetch()works fine.Just want to know how to do git diff local remote using gitpython.
Thanks
hcheruku commentedon Feb 25, 2020
nevermind! I did it.
Here's what I did:
It works!
Thanks for replying
Have a great day ahead :-)