In Visual Studio, if the remote contains work that you don’t have locally, and you try to do a push to that branch, you’ll see the following in Visual Studio Team Explorer:
The output window contains more information:
You’ll resolve this by clicking Pull
Visual Studio will automatically do any merges. Since there are were no conflicts, the auto-merge was successful and created a merge commit.
Now you can simply Push these changes up to the remote.
From the command line
Here’s what the corresponding scary message looks like from command line.
You’ll first want to Git Pull – which will result with Notepad prompting me to update my merge commit message if needed.
And now in Mortal Kombat fashion (I spelled Kombat right this time), you need to Finish It!
and do a Git Push.
A few weeks ago I tried to figure out how to do this, but to no avail. I couldn’t find an answer because the solution is a more of a generic “catch-all” command to get lots of info about a remote, including figuring out which branches were newly added to a remote.
$ git remote show origin
Note how next to the circled `saraford-patch-1` you see the text `new (next featch will store in remotes/origin). Now I know what new branches (if any) I’ll “fetch down” the next time I do a fetch.
Obviously this command shows other goodness, like seeing which local branch talks to which remote branch, and more importantly, what “origin” (or some other specified remote) points to.
Thanks to Jeff (blog comments) for the pointer to `git remote show origin` which answered my question!
And now for the exciting conclusion*
As shown in Tip 118 – how to download and merge commits using Pull in Visual Studio, today’s tip rinse and repeats from the command line.
Unlike this past week, you are ready to fetch changes and merge them all in one command: Pull.
First, checkout the desired branch.
Second, run the following
$ git pull
And git will perform the fetch and merge all at the same time.
*I think my greatest obstacle in learning git commands is knowing when a command or subcommand wants 1. a remote 2. a branch name 3. nothing at all.
Has anyone tried nursery rhymes yet to learn git commands in the same way we learn the names of the planets? I really need to get back into standup comedy.
Today’s tip is the continuation from Tip 118 – how to download and merge from a remote branch into Visual Studio, but using the command line.
Let’s suppose you have a local branch that’s tracking the remote branch (see yesterday’s tip). And let’s say someone has made an update to that remote branch (e.g. they made a commit `newfile.md` via the GitHub UI to the branch). Now you want to get those changes into your local branch.
First, we’ll put this week’s earlier tip to good use by doing a `git fetch` just to get those changes onto your computer.
Now you want to merge those changes into your local branch.
First, make sure you’ve checked out the desired branch to receive the merge.
Second, do the merge from the remote tracking branch (since it has the data)
$ git merge origin/<branch-name>
And now if you do a `dir` or `ls` you’ll see the changes. In my example, the newfile.md is now shown in the local branch.