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

You have not concluded your merge (MERGE_HEAD exists)

OK. The problem is your previous pull failed to merge automatically and went to conflict state. And the conflict wasn’t resolved properly before the next pull. Undo the merge and pull again.To undo a merge:git merge –abort [Since git version 1.7.4]git reset –merge [prior git versions] Resolve the conflict. Don’t forget to add and commit the merge. … Read more

fatal: The current branch master has no upstream branch

You fixed the push, but, independently of that push issue (which I explained in “Why do I need to explicitly push a new branch?“: git push -u origin master or git push -u origin –all), you need now to resolve the authentication issue. That depends on your url (ssh as in ‘[email protected]/yourRepo, or https as in https://github.com/You/YourRepo) For https … Read more

How to cherry-pick multiple commits

Git 1.7.2 introduced the ability to cherry pick a range of commits. From the release notes: git cherry-pick learned to pick a range of commits (e.g. cherry-pick A..B and cherry-pick –stdin), so did git revert; these do not support the nicer sequencing control rebase [-i] has, though. To cherry-pick all the commits from commit A to commit B (where A is older than B), run: If you want to ignore A itself, … Read more

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