I have an account of a Gitlab installation where I created the repository "ffki-startseite"
Now I want to clone the repository git://freifunk.in-kiel.de/ffki-startseite.git
into that repository with all commits and branches, so I can start working on it in my own scope.
How can I import it?
You create an empty project in gitlab then on your local terminal follow one of these:
Push an existing folder
cd existing_folder
git init
git remote add origin [email protected]:GITLABUSERNAME/YOURGITPROJECTNAME.git
git add .
git commit -m "Initial commit"
git push -u origin master
Push an existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin [email protected]:GITLABUSERNAME/YOURGITPROJECTNAME.git
git push -u origin --all
git push -u origin --tags
Add the new gitlab remote to your existing repository and push:
git remote add gitlab url-to-gitlab-repo
git push gitlab master
rake gitlab:import:repos might be a more suitable method for mass importing:
repos_path
(/home/git/repositories/group/repo.git
). Directory name must end in .git
and be under a group or user namespace.bundle exec rake gitlab:import:repos
The owner will the first admin, and a group will get created if not already existent.
See also: How to import an existing bare git repository into Gitlab?
Gitlab is a little bit bugged on this feature. You can lose a lot of time doing troubleshooting specially if your project is any big.
The best solution would be using the create/import tool, do not forget put your user name and password, otherwise it won't import anything at all.
Follow my screenshots
git clone --mirror [email protected]:username/repo-name.git
git remote add gitlab ssh://[email protected]/username/repo.git
git push -f --tags gitlab refs/heads/*:refs/heads/*
It is better to do it over ssh, the https might won't work
To keep ALL TAGS AND BRANCHES
Just simply run this command in an existing Git repository
cd existing_repo
git remote rename origin previous-hosts
git remote add gitlab [email protected]:hutber/kindred.com.git
git push -u gitlab --all
git push -u gitlab --tags
I was able to fully export my project along with all commits, branches and tags to gitlab via following commands run locally on my computer:
To illustrate my example, I will be using https://github.com/raveren/kint as the source repository that I want to import into gitlab. I created an empty project named
Kint
(under namespaceraveren
) in gitlab beforehand and it told me the http git url of the newly created project there is http://gitlab.example.com/raveren/kint.gitThe commands are OS agnostic.
In a new directory:
git clone --mirror https://github.com/raveren/kint
cd kint.git
git remote add gitlab http://gitlab.example.com/raveren/kint.git
git push gitlab --mirror
Now if you have a locally cloned repository that you want to keep using with the new remote, just run the following commands* there:
git remote remove origin
git remote add origin http://gitlab.example.com/raveren/kint.git
git fetch --all
*This assumes that you did not rename your remote master from origin
, otherwise, change the first two lines to reflect it.
This is a basic move one repo to new location. I use this sequence all te time. With --bare no source files will be seen.
Open Git Bash.
Create a bare clone of the repository.
git clone --bare https://github.com/exampleuser/old-repository.git
Mirror-push to the new repository.
cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
Remove the temporary local repository you created in step 1.
cd ../
rm -rf old-repository.git
Why mirror? See documentation of git: https://git-scm.com/docs/git-push
--all Push all branches (i.e. refs under refs/heads/); cannot be used with other .
--mirror Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote..mirror is set.
Here are the steps provided by the Gitlab:
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.example.com/rmishra/demoapp.git
git push -u origin --all
git push -u origin --tags
Source: Stackoverflow.com