How to Import specific folder of github repo to gitlab

Hi,

you can only create imports on the project level, not repository directories.

If you are looking for a boring solution with does not preserve Git history, write a script to clone the GitHub repository locally, copy the directory into a new Git repo, and push that to GitLab. The following takes the trick into account to create a private repo on a fresh push.

Should work like below, I wrote that from memory but did not test working.

export PROJECT=project
export USER=user
export DIRECTORY=directory

export GITLAB_NAMESPACE=user
export GITLAB_PROJECT="$PROJECT-$DIRECTORY"
mkdir migration && cd migration

# path for GitLab repo
mkdir -p $GITLAB_PROJECT

git clone https://github.com/$USER/$PROJECT.git 

# copy the data into a new repository
cp -rv "$PROJECT/$DIRECTORY/*" "$GITLAB_PROJECT/"

# init, add, remote, push 
cd $GITLAB_PROJECT
git init
git add -A
git commit -av -m "Import GH $DIRECTORY to GL $GITLAB_PROJECT"
git remote add origin https://gitlab.com/$GITLAB_NAMESPACE/$GITLAB_PROJECT.git
git push -u origin --all

Cheers,
Michael

1 Like