Search code examples
gitlibgit2sharp

Perform a pull without a checkout with Libgit2sharp


I'd like to perform a pull from a remote branch to a local branch without having to checkout the local branch. I've seen this done in tools like GitKraken and have found a command line solution here: https://stackoverflow.com/a/17722977/1326370. However, I haven't been able to figure out how to do this with Libgit2sharp. Any ideas?


Solution

  • You cannot merge a remote into your local without checking that out first. git pull is equal to git fetch ; git merge, and git merge always merges something into the "current" branch (i.e., the HEAD checked out in your working directory).

    Now, if you do not actually need a merge-pull because you want to throw your local version of the branch away, then you can do git branch -D mybranch ; git fetch ; git branch mybranch origin/mybranch without checking out anything. I assume your library should support those commands.