Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created

@param string $branch
@param string $stash
420527
public function stashBranch(string $branch, string $stash)
    {
        $stashCommand = StashCommand::getInstance($this);
        $command = $stashCommand->branch($branch, $stash);
        $this->caller->execute($command);
    }
570088
def setup_environment
      store_modified_times
      Overcommit::GitRepo.store_merge_state
      Overcommit::GitRepo.store_cherry_pick_state

      if !initial_commit? && any_changes?
        @stash_attempted = true

        stash_message = "Overcommit: Stash of repo state before hook run at #{Time.now}"
        result = Overcommit::Utils.execute(
          %w[git -c commit.gpgsign=false stash save --keep-index --quiet] + [stash_message]
        )

        unless result.success?
          # Failure to stash in this case is likely due to a configuration
          # issue (e.g. author/email not set or GPG signing key incorrect)
          raise Overcommit::Exceptions::HookSetupFailed,
                "Unable to setup environment for #{hook_script_name} hook run:" \
                "\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
        end

        @changes_stashed = `git stash list -1`.include?(stash_message)
      end

      # While running the hooks make it appear as if nothing changed
      restore_modified_times
    end
683331
def amendPrevious(self, targethash):
        ''

        prevBranch = loggit_all('rev-parse', '--symbolic-full-name', '--abbrev-ref', 'HEAD').strip()

        ret = loggit_all('commit', '-m', 'MERGE '+targethash) # commit index to viewed branch
        newChanges = loggit_all('rev-parse', 'HEAD').strip()

        ret += loggit_all('stash', 'save', '--keep-index') # stash everything else
        with GitUndo('stash', 'pop'):
            tmpBranch = randomBranchName()
            ret += loggit_all('checkout', '-b', tmpBranch) # create/switch to tmp branch
            with GitUndo('checkout', prevBranch), GitUndo('branch', '-D', tmpBranch):
                ret += loggit_all('reset', '--hard', targethash) # tmpbranch now at targethash
                ret += loggit_all('cherry-pick', '-n', newChanges)  # pick new change from original branch
                ret += loggit_all('commit', '--amend', '--no-edit')  # recommit to fix targethash (which will change)
                ret += loggit_all('rebase', '--onto', tmpBranch, 'HEAD@{1}', prevBranch)  # replay the rest

        return ret.splitlines()
547940
protected function validateBranch($branch)
    {
        try {
            if (!strpos($branch, '/')) {
                return false;
            }
            return $this->versionParser->normalizeBranch(
                $this->_getBranchWithoutNamespace($branch)
            );
        } catch (\Exception $e) {
            return false;
        }
    }
123841
public function branchExists($branchName, $dir = null, $mustRun = false)
    {
        // The porcelain command 'git branch' is less strict about character
        // encoding than (otherwise simpler) plumbing commands such as
        // 'git show-ref'.
        $result = $this->execute(['branch', '--list', '--no-color', '--no-column'], $dir, $mustRun);
        $branches = array_map(function ($line) {
            return trim(ltrim($line, '* '));
        }, explode("\n", $result));

        return in_array($branchName, $branches, true);
    }
741274
def stash(self, stash_name: str):
        
        if self.stashed:
            LOGGER.error('already stashed')
            sys.exit(-1)
        else:
            if not self.index_is_empty():
                LOGGER.error('cannot stash; index is not empty')
                sys.exit(-1)
            if self.untracked_files():
                LOGGER.error('cannot stash; there are untracked files')
                sys.exit(-1)
            if self.changed_files():
                LOGGER.info('stashing changes')
                self.repo.git.stash('push', '-u', '-k', '-m', f'"{stash_name}"')
                self.stashed = True
            else:
                LOGGER.info('no changes to stash')
121824
public function createFile(string $path, string $message, string $content,
                               string $branch = AbstractApi::BRANCH_MASTER): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/contents/:path?:args',
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $path,
            http_build_query(['message' => $message, 'content' => $content, 'branch' => $branch])),
            Request::METHOD_PUT);
    }
525883
protected function hasGitBranch($branch_name)
    {
        $task = $this->getGitBuildStack()
            ->exec("rev-parse -q --verify {$branch_name}");

        $result = $this->runSilentCommand($task);

        return !empty($result->getMessage());
    }
1074803
public function show($stash = null)
    {
        $this->arguments[] = 'show';
        if ($stash) {
            $this->arguments[] = 'stash@{' . $stash . '}';
        }
        return $this->run();
    }
1113963
public function pass($branchNumber, StatementsBlock $block)
    {
        $this->passStatementBlock($branchNumber, $block->getStatements());
        $this->branches[$branchNumber] = 0;
    }
682387
def create_branches(self, branches):
        
        if not isinstance(branches, TreeBuffer):
            branches = TreeBuffer(branches)
        self.set_buffer(branches, create_branches=True)
289028
public function push($remote = null, $branch = null)
    {
        $result = $this->command . ' push ' . $remote . ' ' . $branch;
        return $result;
    }
759611
public Ref checkoutBranch(Git git, String branch) {
        try {
            return git.checkout()
                .setName(branch)
                .call();
        } catch (GitAPIException e) {
            throw new IllegalStateException(e);
        }
    }
345575
public void removeTransaction(String branch) {
		synchronized(this.ongoingTransactions) {
			TransactionRequest remove = null;
			for(TransactionRequest tr : this.ongoingTransactions) {
				if(tr.branchId.equals(branch)) {
					remove = tr;
					break;
				}
			}
			if(remove != null) {
				boolean removed = this.ongoingTransactions.remove(remove);
				if(logger.isDebugEnabled()) {
					logger.debug("Removed transaction " + branch + " from proxy branch ? " + removed);
				}
			} else {
				if(logger.isDebugEnabled()) {
					logger.debug("Removing transaction " + branch + " from proxy branch FAILED. Not found.");
				}
			}
		}
	}
1001789
void checkout(File project, String branch) {
		try {
			String currentBranch = currentBranch(project);
			if (currentBranch.equals(branch)) {
				log.info("Won't check out the same branch. Skipping");
				return;
			}
			log.info("Checking out branch [" + branch + "]");
			checkoutBranch(project, branch);
			log.info("Successfully checked out the branch [" + branch + "]");
		}
		catch (Exception e) {
			throw new IllegalStateException(e);
		}
	}
630021
private function doSaveStash()
    {
        $pending = $this->repository->getWorkingCopy()->getDiffPending();
        if (!\count($pending->getFiles())) {
            return;
        }

        try {
            $this->io->write(['<fg=yellow>Detected unstaged changes... Stashing them!</fg=yellow>']);
            $this->repository->run('stash', ['save', '--quiet', '--keep-index', uniqid('grumphp')]);
        } catch (Exception $e) {
            // No worries ...
            $this->io->write([sprintf('<fg=red>Failed stashing changes: %s</fg=red>', $e->getMessage())]);

            return;
        }

        $this->stashIsApplied = true;
        $this->registerShutdownHandler();
    }
817831
def create_branch(self, new_branch, delete_empty=False):
        
        logger.info("Preparing to create branch {} from {}".format(new_branch, self.config.branch))
        try:
            # create new branch
            self.provider.create_branch(
                base_branch=self.config.branch,
                new_branch=new_branch,
                repo=self.user_repo
            )
            logger.info("Created branch {} from {}".format(new_branch, self.config.branch))
            return True
        except BranchExistsError:
            logger.info("Branch {} exists.".format(new_branch))
            # if the branch exists, is empty and delete_empty is set, delete it and call
            # this function again
            if delete_empty:
                if self.provider.is_empty_branch(self.user_repo, self.config.branch, new_branch,
                                                 self.config.branch_prefix):
                    self.provider.delete_branch(self.user_repo, new_branch,
                                                self.config.branch_prefix)
                    logger.info("Branch {} was empty and has been deleted".format(new_branch))
                    return self.create_branch(new_branch, delete_empty=False)
                logger.info("Branch {} is not empty".format(new_branch))
        return False