43

First, as the title says, is it even possible in a single step (i.e. not fetch then rebase), to do a pull --rebase?

Second, is a setting in Visual Studio to force the built-in Team Explorer git tools to always do a pull --rebase rather than a standard pull (fetch/merge).

I am aware you could set the default in the global or project config files with git config branch.autosetuprebase always, but I wanted to specifically find out if Visual Studio could update/change that setting or had a similar option, like most other GUIs have. I haven't been able to find anything, so it seems like it doesn't, hence the question.

LocalPCGuy
  • 6,006
  • 2
  • 32
  • 28
  • 1
    Use the IDE for IDE stuff and versioning tools for versioning stuff http://stackoverflow.com/q/19358148/520162. I don't know any IDE that could properly cope with the power of Git, so I use the only true interface to Git, the command line. However, I wouldn't start debugging or programming with the command line. That's where IDEs usually excel. – eckes Apr 02 '15 at 10:34
  • 1
    Personally I agree with you, but my question is very specific because there are others that may buy into using the IDE ecosystem for as much as possible. I'm looking to minimize their disruption while still managing git best practices. If the end answer is just use the CLI or a tool like SourceTree, it's nice to have concrete reasons why, like you can't do X with the IDE – LocalPCGuy Apr 02 '15 at 12:12
  • @NathanOliver I based my edit off OP's comment on the answer below. – Carrie Kendall Jul 14 '15 at 14:11
  • 1
    @CarrieKendall I didn't even think to look at the answer. Thanks. – NathanOliver Jul 14 '15 at 14:12
  • 1
    +1 for `git config branch.autosetuprebase always`. That's my new knowledge for today, no more until tomorrow please. – Paul Hicks Aug 27 '15 at 01:51
  • 4
    Gotta vote to get that one in: https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/10294356-sync-button-should-allow-git-pull-rebase – laurencee Feb 24 '16 at 03:58

4 Answers4

26

In VS2017 you can use built-in feature to change git settings for rebase: go to Team Explorer -> Home -> Settings -> Global Settings or Repository Settings -> set Rebase local branch when pulling: True (screenshot)

Woonder
  • 291
  • 4
  • 4
  • Any idea if there's something I can check into source control so this becomes the default for other team members too for a particular repo? Or does that have to be shared through visual studio policies of some kind? – mutex Jun 02 '20 at 23:35
  • docs link : https://learn.microsoft.com/en-us/azure/devops/repos/git/pulling?view=azure-devops&tabs=visual-studio-2019 – gawkface May 06 '22 at 22:18
15

Visual Studio 2015 does not support pull+rebase. You can achieve it manually by performing a fetch of 'branch' and then do a rebase onto 'origin/branch'. But not automatically.

Visual Studio 2017 (release candidate) will currently perform the pull+rebase if it's configured as default option in your global git settings. It does currently still give you an warning saying "unexpected merge result". I'm hoping this will be fixed before the final version comes out.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
1

Open Git Bash and paste:

git config --global branch.autosetuprebase always

This will make every future pull a pull --rebase.

GaloisGirl
  • 1,476
  • 1
  • 8
  • 14
  • This setting is not supported by the git client implementation in Visual Studio 2015. – jessehouwing Jan 18 '17 at 21:20
  • It works for me, although, if you have uncommited changes, it will fallback to a normal pull. I have yet to find "git stash" in Visual Studio. – GaloisGirl Jan 19 '17 at 21:58
  • It does an auto stash/unstash when switching branches. Otherwise it doesn't have support for stash, you could just create another temporary branch instead. – jessehouwing Jan 20 '17 at 05:55
  • 1
    Visual Studio ignores any settings you've changed when it comes to pulling. Doing a pull while not having any local changes will result in a fast-forward (so no merge commit). I've changed the setting you provided (and set `pull.rebase preserve` as well) and with local changes it sitll creates a merge commit. Vs does a `pull --no-rebase` whenever you hit sync (source: https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/10294356-sync-button-should-allow-git-pull-rebase ) – Toolmaker Mar 30 '17 at 08:43
0

This is as close as you can get to doing an actual rebase pull.

First do a fetch on the remote you want to rebase onto. It won't be a "pull --rebase" but you can go to team explorer > branches > remotes > (choose your remote) > right click on the branch you want to rebase onto and click rebase onto click rebase and you have basically done a pull/rebase onto the remote branch.

(but currently this is the only way to rebase onto remote updates without running to a git bash)

gabeio
  • 1,282
  • 1
  • 23
  • 37