I am trying to diff
my local file with a GitHub repository before I submit a pull request, so I can see what will show up. Is there an accurate way of doing this?
I assume GitHub's compare tool manipulates Git's diff
.
The git fetch command will fetch all changes that happened in the origin. And the git diff will show us the differents files between our working tree and the remote.
Git local repository is the one on which we will make local changes, typically this local repository is on our computer. Git remote repository is the one of the server, typically a machine situated at 42 miles away.
A remote repository in Git, also called a remote, is a Git repository that's hosted on the Internet or another network. Watch this beginner Git tutorial video to learn how to Git clone a remote repository to create a local version of the repository on your machine.
1 Answer. You can use git branch -a to list all branches then choose the branch name from the list from the remote branch name. Example: git diff master origin/master (where "master" is a local master branch and "origin/master" is a remote namely origin and master branch.)
To compare a local working directory against a remote branch, for example origin/master:
git fetch origin master
git fetch
will not affect the files in your working directory; it does not try to merge changes like git pull
does. git diff --summary FETCH_HEAD
--stat
instead of --summary
. git diff FETCH_HEAD -- mydir/myfile.js
--summary
option and reference the file you want (or tree).As noted, origin
references the remote repository and master
references the branch within that repo. By default, git uses the name origin
for a remote, so if you do git clone <url>
it will by default call that remote origin
. Use git remote -v
to see what origin
points to.
You may have more than one remote. For example, if you "fork" a project on GitHub, you typically need a remote referencing the original project as well as your own fork. Say you create https://github.com/yourusername/someproject
as a fork of https://github.com/theoriginal/someproject
. By convention, you would name the remote to the original repo upstream
, while your own fork would be origin
. If you make changes to your fork on GitHub and want to fetch those changes locally, you would use git fetch origin master
. If the upstream
has made changes that you need to sync locally before making more changes, you would use git fetch upstream master
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With