Skip to content

Instantly share code, notes, and snippets.

@asgrim
Last active February 1, 2022 08:38
Show Gist options
  • Save asgrim/05d2dfe7ad802d88993c9f990d65d4c7 to your computer and use it in GitHub Desktop.
Save asgrim/05d2dfe7ad802d88993c9f990d65d4c7 to your computer and use it in GitHub Desktop.
GitLab checkout process - example of how to replicate a git checkout that GitLab does (more or less)
mkdir project-checkout
cd project-checkout
# https://gitlab.com/gitlab-org/gitlab-runner/-/blob/b41ed180/shells/abstract.go#L353
git init
# https://gitlab.com/gitlab-org/gitlab-runner/-/blob/b41ed180/shells/abstract.go#L357
git remote add origin <remote_url>
# https://gitlab.com/gitlab-org/gitlab-runner/-/blob/b41ed180/shells/abstract.go#L366
# build.GitInfo.Refspecs is defined: https://gitlab.com/gitlab-org/gitlab-runner/-/blob/9d8d6f93/common/support.go#L58
git fetch origin +refs/heads/*:refs/origin/heads/* +refs/tags/*:refs/tags/*
# https://gitlab.com/gitlab-org/gitlab-runner/-/blob/b41ed180/shells/abstract.go#L402
git checkout -f <commit_sha_of_the_build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment