rejected master -> master (non-fast-forward)

As the error message says: git pull before you try to git push. Apparently your local branch is out of sync with your tracking branch. Depending on project rules and your workflow you might also want to use git pull –rebase.

How can I git stash a specific file?

EDIT: Since git 2.13, there is a command to save a specific path to the stash: git stash push <path>. For example: OLD ANSWER: You can do that using git stash –patch (or git stash -p) — you’ll enter interactive mode where you’ll be presented with each hunk that was changed. Use n to skip the files that you don’t want to … Read more

How do you create a remote Git branch?

Simple Git 2.0+ solution: As of Git 2.0, the behavior has become simpler: You can configure git with push.default = current to make life easier: I added this so now I can just push a new branch upstream with -u will track remote branch of the same name. Now with this configuration, you will auto-guess the remote reference to … Read more

Why do I have to “git push –set-upstream origin “?

TL;DR: git branch –set-upstream-to origin/solaris The answer to the question you asked—which I’ll rephrase a bit as “do I have to set an upstream”—is: no, you don’t have to set an upstream at all. If you do not have upstream for the current branch, however, Git changes its behavior on git push, and on other commands as well. The … Read more

How to compare files from two different branches

git diff can show you the difference between two commits: Or, equivalently: Note you must specify the relative path to the file. So if the file were in the src directory, you’d say src/myfile.cs instead of myfile.cs. Using the latter syntax, if either side is HEAD it may be omitted (e.g., master.. compares master to HEAD). You may also be interested in mybranch…master (from git diff documentation): This form is … Read more