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?
Asked
Active
Viewed 361 times
1 Answers
1
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.

AnoE
- 8,048
- 1
- 21
- 36
-
This was my understanding too, until I read the answer that I linked to. In summary that says that for a fast-forward merge you can do `git fetch
: ` -
Yes, for a fast-forward you can use whatever variant (mine is a bit more clear since it only uses standard commands and hence likely available in some library). I assumed you asked your question because you did not find how to do "your" `git fetch` variant in that library? – AnoE Jul 26 '16 at 12:34
-
Sorry, I misunderstood your suggestion. You're absolutely right that I don't know how to implement "my" solution using Libgit2sharp, but the solution you've suggested is easy to implement because it uses simple operations that are already available. Thanks! – sclarke81 Jul 26 '16 at 13:24