One of the things that can make git hard to think about is that there are at least four different “repositories” you’re shuffling files between: your worktree, the index, your local repo, and your upstream repo.
To see the differences between your worktree and your index (to see what you need to add), you can use git diff
.
To see the differences between your index and your local repo (to see what you’re about to commit), you can use git diff --cached
.
But extending the pattern, is there a good way to view differences between your local repo and your upstream, before you do a git push
, to double-check that what you’re about to push is what you really want to push?
I ask because it’s not actually that hard to push things you didn’t mean to push. For example, if you’ve done something like a git merge --nocommit
on your local branch, I believe that gives you a bunch of “invisible” local changes, that git diff
will never show, but that will affect your upstream repo — in ways you maybe didn’t intend — next time you push.
Update: Whoops, the “Check your question” thingie didn’t detect any dups, but a google search did:
-
How can I see what I am about to push with git?
-
List Git commits not pushed to the origin yet
-
Preview a Git push
-
How to list unpushed Git commits (local but not on origin)
I haven’t digested the answers to those yet, but as soon as I do, I’ll probably delete this question.