How to Import specific folder of github repo to gitlab

I would like to migrate a specific folder from a repo that is in Github to Gitlab. can someone help me with this?

I tried this command sudo gitlab-rake "import:github[access_token,root,foo/bar,foo/github_repo/folder]" it didn’t work for me. GitHub import | GitLab

can some one help me on this


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

mkdir migration && cd migration

# path for GitLab repo

git clone$USER/$PROJECT.git 

# copy the data into a new repository

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


1 Like

Thank you Mike for throwing some suggestions. I tried a different approach

  1. I imported the entire repo of Github to Gitlab
  2. I deleted the directories that I don’t want from the project in Gitlab
  3. Now I have the only directory that I want

Problem: I expected that corresponding commits of the directories (deleted directories) will be deleted but it didn’t happen. I still have the same number of commits, branches, Merge requests even after I delete directories. to fix this is there any option that I need to enable?