public function syncWithRemote($remote, $branchName = null)
{
$this->guardWorkingTreeReady();
$activeBranchName = $this->getActiveBranchName($branchName);
$this->stashBranchName();
if (null === $branchName) {
$branchName = $activeBranchName;
}
$this->remoteUpdate($remote);
if ($activeBranchName !== $branchName) {
$this->checkout($branchName);
}
$this->reset('HEAD~1', 'hard');
$this->pullRemote($remote, $branchName, true);
if ($activeBranchName !== $branchName) {
$this->checkout($activeBranchName);
}
}