How to transfer existing git repo from local server to gitlab repo, using CLI(Shell script)?
I have many git repos on my server. Using command line(script) I want to make new gitlab repos on https://gitlab.companyname.com, form existing local repos. And also push all branches with tags on gitLab server.
Is it possible to do that without enterprise account?
git shell github gitlab command-line-interface
add a comment |
I have many git repos on my server. Using command line(script) I want to make new gitlab repos on https://gitlab.companyname.com, form existing local repos. And also push all branches with tags on gitLab server.
Is it possible to do that without enterprise account?
git shell github gitlab command-line-interface
git push --all
should take care of the "all branches and tags" requirement
– OhleC
Nov 13 '18 at 9:44
@ohlec Agree. but I need to clone all projects into local directory(from local server) then need to transfer cloned project on gitlab server.
– SuvaP
Nov 13 '18 at 9:55
add a comment |
I have many git repos on my server. Using command line(script) I want to make new gitlab repos on https://gitlab.companyname.com, form existing local repos. And also push all branches with tags on gitLab server.
Is it possible to do that without enterprise account?
git shell github gitlab command-line-interface
I have many git repos on my server. Using command line(script) I want to make new gitlab repos on https://gitlab.companyname.com, form existing local repos. And also push all branches with tags on gitLab server.
Is it possible to do that without enterprise account?
git shell github gitlab command-line-interface
git shell github gitlab command-line-interface
edited Nov 13 '18 at 10:11
SuvaP
asked Nov 13 '18 at 9:42
SuvaPSuvaP
245
245
git push --all
should take care of the "all branches and tags" requirement
– OhleC
Nov 13 '18 at 9:44
@ohlec Agree. but I need to clone all projects into local directory(from local server) then need to transfer cloned project on gitlab server.
– SuvaP
Nov 13 '18 at 9:55
add a comment |
git push --all
should take care of the "all branches and tags" requirement
– OhleC
Nov 13 '18 at 9:44
@ohlec Agree. but I need to clone all projects into local directory(from local server) then need to transfer cloned project on gitlab server.
– SuvaP
Nov 13 '18 at 9:55
git push --all
should take care of the "all branches and tags" requirement– OhleC
Nov 13 '18 at 9:44
git push --all
should take care of the "all branches and tags" requirement– OhleC
Nov 13 '18 at 9:44
@ohlec Agree. but I need to clone all projects into local directory(from local server) then need to transfer cloned project on gitlab server.
– SuvaP
Nov 13 '18 at 9:55
@ohlec Agree. but I need to clone all projects into local directory(from local server) then need to transfer cloned project on gitlab server.
– SuvaP
Nov 13 '18 at 9:55
add a comment |
3 Answers
3
active
oldest
votes
My frined built a script (curl, git, jq required) just for that. We use it and it works just fine: https://gist.github.com/JonasGroeger/1b5155e461036b557d0fb4b3307e1e75
To find out your namespace, its best to check the API quick:
curl "https://example.com/api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN"
There, use "namespace.name" as NAMESPACE for your group.
The script essentially does:
Get all Projects that match your PROJECT_SEARCH_PARAM
Get their path and ssh_url_to_repo
If the directory path exists, cd into it and call git pull
If the directory path does not exist, call git clone
add a comment |
Save below file by filename.sh
- open terminal
- goto file saved directory
- type "sh filename.sh" command and hit enter
Here all the projects from local server are moved to your GitLab server by using this shell script.
# Below is project directory where we are clone all projects
cd /Users/abcd.pqrs/Documents/dev/AllProjects
#Private Tocken
declare projectTocken="YourProjectTockenString"
declare namespaceId=111 #(Your NameSpceId from GitLab)
# Source Repo Array
declare -a source_urls=(
"git@source_Server_IP:/home/git/project_code/projects/project1.git"
"git@source_Server_IP:/home/git/project_code/projects/project2.git"
"git@source_Server_IP:/home/git/project_code/projects/project3.git"
)
# Project Names by using *Source Repo* URL Array
declare -a project_names=(
"project1"
"project2"
"project3"
)
# *Destination Repo* URLs
declare -a target_urls=(
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
)
## now loop through the above Source URL array
for i in "${!source_urls[@]}"
do
# Clone the project into local directory
echo "Clonning ${source_urls[$i]}"
git clone "${source_urls[$i]}"
# Go to project folder/directory
cd "${project_names[$i]}"
# Create New Project on Gitlab
curl -H "Content-Type:application/json" http://destination_Server_IP/api/v4/projects?private_token="$projectTocken" -d "{ "name": "${project_names[$i]}", "namespace_id": "$namespaceId" }"
# Set the new server URL for this new directory
git remote set-url origin "${target_urls[$i]}"
for remote in `git branch -r | grep -v /HEAD`; do
echo "Switching to $remote Branch"
#Track all the remote branches into local repo
git checkout --track $remote ;
git status
done
#Push All branches to new server
git push origin --all
# Move back to Mobility directory so that next repo will start with new directory in same folder
cd -
pwd
done
Edit this script as per requirement.
add a comment |
You can add your gitlab repo as a remote in your server. Then you can use push --all.
Something like this in each repo directory you have:
git add remote gitlab <YOUR NEW REPO URL>
git push gitlab --all
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278029%2fhow-to-transfer-existing-git-repo-from-local-server-to-gitlab-repo-using-clish%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
My frined built a script (curl, git, jq required) just for that. We use it and it works just fine: https://gist.github.com/JonasGroeger/1b5155e461036b557d0fb4b3307e1e75
To find out your namespace, its best to check the API quick:
curl "https://example.com/api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN"
There, use "namespace.name" as NAMESPACE for your group.
The script essentially does:
Get all Projects that match your PROJECT_SEARCH_PARAM
Get their path and ssh_url_to_repo
If the directory path exists, cd into it and call git pull
If the directory path does not exist, call git clone
add a comment |
My frined built a script (curl, git, jq required) just for that. We use it and it works just fine: https://gist.github.com/JonasGroeger/1b5155e461036b557d0fb4b3307e1e75
To find out your namespace, its best to check the API quick:
curl "https://example.com/api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN"
There, use "namespace.name" as NAMESPACE for your group.
The script essentially does:
Get all Projects that match your PROJECT_SEARCH_PARAM
Get their path and ssh_url_to_repo
If the directory path exists, cd into it and call git pull
If the directory path does not exist, call git clone
add a comment |
My frined built a script (curl, git, jq required) just for that. We use it and it works just fine: https://gist.github.com/JonasGroeger/1b5155e461036b557d0fb4b3307e1e75
To find out your namespace, its best to check the API quick:
curl "https://example.com/api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN"
There, use "namespace.name" as NAMESPACE for your group.
The script essentially does:
Get all Projects that match your PROJECT_SEARCH_PARAM
Get their path and ssh_url_to_repo
If the directory path exists, cd into it and call git pull
If the directory path does not exist, call git clone
My frined built a script (curl, git, jq required) just for that. We use it and it works just fine: https://gist.github.com/JonasGroeger/1b5155e461036b557d0fb4b3307e1e75
To find out your namespace, its best to check the API quick:
curl "https://example.com/api/v3/projects?private_token=$GITLAB_PRIVATE_TOKEN"
There, use "namespace.name" as NAMESPACE for your group.
The script essentially does:
Get all Projects that match your PROJECT_SEARCH_PARAM
Get their path and ssh_url_to_repo
If the directory path exists, cd into it and call git pull
If the directory path does not exist, call git clone
answered Nov 13 '18 at 10:54
Istiyak AminIstiyak Amin
15313
15313
add a comment |
add a comment |
Save below file by filename.sh
- open terminal
- goto file saved directory
- type "sh filename.sh" command and hit enter
Here all the projects from local server are moved to your GitLab server by using this shell script.
# Below is project directory where we are clone all projects
cd /Users/abcd.pqrs/Documents/dev/AllProjects
#Private Tocken
declare projectTocken="YourProjectTockenString"
declare namespaceId=111 #(Your NameSpceId from GitLab)
# Source Repo Array
declare -a source_urls=(
"git@source_Server_IP:/home/git/project_code/projects/project1.git"
"git@source_Server_IP:/home/git/project_code/projects/project2.git"
"git@source_Server_IP:/home/git/project_code/projects/project3.git"
)
# Project Names by using *Source Repo* URL Array
declare -a project_names=(
"project1"
"project2"
"project3"
)
# *Destination Repo* URLs
declare -a target_urls=(
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
)
## now loop through the above Source URL array
for i in "${!source_urls[@]}"
do
# Clone the project into local directory
echo "Clonning ${source_urls[$i]}"
git clone "${source_urls[$i]}"
# Go to project folder/directory
cd "${project_names[$i]}"
# Create New Project on Gitlab
curl -H "Content-Type:application/json" http://destination_Server_IP/api/v4/projects?private_token="$projectTocken" -d "{ "name": "${project_names[$i]}", "namespace_id": "$namespaceId" }"
# Set the new server URL for this new directory
git remote set-url origin "${target_urls[$i]}"
for remote in `git branch -r | grep -v /HEAD`; do
echo "Switching to $remote Branch"
#Track all the remote branches into local repo
git checkout --track $remote ;
git status
done
#Push All branches to new server
git push origin --all
# Move back to Mobility directory so that next repo will start with new directory in same folder
cd -
pwd
done
Edit this script as per requirement.
add a comment |
Save below file by filename.sh
- open terminal
- goto file saved directory
- type "sh filename.sh" command and hit enter
Here all the projects from local server are moved to your GitLab server by using this shell script.
# Below is project directory where we are clone all projects
cd /Users/abcd.pqrs/Documents/dev/AllProjects
#Private Tocken
declare projectTocken="YourProjectTockenString"
declare namespaceId=111 #(Your NameSpceId from GitLab)
# Source Repo Array
declare -a source_urls=(
"git@source_Server_IP:/home/git/project_code/projects/project1.git"
"git@source_Server_IP:/home/git/project_code/projects/project2.git"
"git@source_Server_IP:/home/git/project_code/projects/project3.git"
)
# Project Names by using *Source Repo* URL Array
declare -a project_names=(
"project1"
"project2"
"project3"
)
# *Destination Repo* URLs
declare -a target_urls=(
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
)
## now loop through the above Source URL array
for i in "${!source_urls[@]}"
do
# Clone the project into local directory
echo "Clonning ${source_urls[$i]}"
git clone "${source_urls[$i]}"
# Go to project folder/directory
cd "${project_names[$i]}"
# Create New Project on Gitlab
curl -H "Content-Type:application/json" http://destination_Server_IP/api/v4/projects?private_token="$projectTocken" -d "{ "name": "${project_names[$i]}", "namespace_id": "$namespaceId" }"
# Set the new server URL for this new directory
git remote set-url origin "${target_urls[$i]}"
for remote in `git branch -r | grep -v /HEAD`; do
echo "Switching to $remote Branch"
#Track all the remote branches into local repo
git checkout --track $remote ;
git status
done
#Push All branches to new server
git push origin --all
# Move back to Mobility directory so that next repo will start with new directory in same folder
cd -
pwd
done
Edit this script as per requirement.
add a comment |
Save below file by filename.sh
- open terminal
- goto file saved directory
- type "sh filename.sh" command and hit enter
Here all the projects from local server are moved to your GitLab server by using this shell script.
# Below is project directory where we are clone all projects
cd /Users/abcd.pqrs/Documents/dev/AllProjects
#Private Tocken
declare projectTocken="YourProjectTockenString"
declare namespaceId=111 #(Your NameSpceId from GitLab)
# Source Repo Array
declare -a source_urls=(
"git@source_Server_IP:/home/git/project_code/projects/project1.git"
"git@source_Server_IP:/home/git/project_code/projects/project2.git"
"git@source_Server_IP:/home/git/project_code/projects/project3.git"
)
# Project Names by using *Source Repo* URL Array
declare -a project_names=(
"project1"
"project2"
"project3"
)
# *Destination Repo* URLs
declare -a target_urls=(
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
)
## now loop through the above Source URL array
for i in "${!source_urls[@]}"
do
# Clone the project into local directory
echo "Clonning ${source_urls[$i]}"
git clone "${source_urls[$i]}"
# Go to project folder/directory
cd "${project_names[$i]}"
# Create New Project on Gitlab
curl -H "Content-Type:application/json" http://destination_Server_IP/api/v4/projects?private_token="$projectTocken" -d "{ "name": "${project_names[$i]}", "namespace_id": "$namespaceId" }"
# Set the new server URL for this new directory
git remote set-url origin "${target_urls[$i]}"
for remote in `git branch -r | grep -v /HEAD`; do
echo "Switching to $remote Branch"
#Track all the remote branches into local repo
git checkout --track $remote ;
git status
done
#Push All branches to new server
git push origin --all
# Move back to Mobility directory so that next repo will start with new directory in same folder
cd -
pwd
done
Edit this script as per requirement.
Save below file by filename.sh
- open terminal
- goto file saved directory
- type "sh filename.sh" command and hit enter
Here all the projects from local server are moved to your GitLab server by using this shell script.
# Below is project directory where we are clone all projects
cd /Users/abcd.pqrs/Documents/dev/AllProjects
#Private Tocken
declare projectTocken="YourProjectTockenString"
declare namespaceId=111 #(Your NameSpceId from GitLab)
# Source Repo Array
declare -a source_urls=(
"git@source_Server_IP:/home/git/project_code/projects/project1.git"
"git@source_Server_IP:/home/git/project_code/projects/project2.git"
"git@source_Server_IP:/home/git/project_code/projects/project3.git"
)
# Project Names by using *Source Repo* URL Array
declare -a project_names=(
"project1"
"project2"
"project3"
)
# *Destination Repo* URLs
declare -a target_urls=(
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
"http://destination_Server_IP/groupName/project1.git"
)
## now loop through the above Source URL array
for i in "${!source_urls[@]}"
do
# Clone the project into local directory
echo "Clonning ${source_urls[$i]}"
git clone "${source_urls[$i]}"
# Go to project folder/directory
cd "${project_names[$i]}"
# Create New Project on Gitlab
curl -H "Content-Type:application/json" http://destination_Server_IP/api/v4/projects?private_token="$projectTocken" -d "{ "name": "${project_names[$i]}", "namespace_id": "$namespaceId" }"
# Set the new server URL for this new directory
git remote set-url origin "${target_urls[$i]}"
for remote in `git branch -r | grep -v /HEAD`; do
echo "Switching to $remote Branch"
#Track all the remote branches into local repo
git checkout --track $remote ;
git status
done
#Push All branches to new server
git push origin --all
# Move back to Mobility directory so that next repo will start with new directory in same folder
cd -
pwd
done
Edit this script as per requirement.
answered Nov 26 '18 at 7:17
community wiki
SuvaP
add a comment |
add a comment |
You can add your gitlab repo as a remote in your server. Then you can use push --all.
Something like this in each repo directory you have:
git add remote gitlab <YOUR NEW REPO URL>
git push gitlab --all
add a comment |
You can add your gitlab repo as a remote in your server. Then you can use push --all.
Something like this in each repo directory you have:
git add remote gitlab <YOUR NEW REPO URL>
git push gitlab --all
add a comment |
You can add your gitlab repo as a remote in your server. Then you can use push --all.
Something like this in each repo directory you have:
git add remote gitlab <YOUR NEW REPO URL>
git push gitlab --all
You can add your gitlab repo as a remote in your server. Then you can use push --all.
Something like this in each repo directory you have:
git add remote gitlab <YOUR NEW REPO URL>
git push gitlab --all
answered Nov 13 '18 at 10:38
gustavovelascohgustavovelascoh
5321418
5321418
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278029%2fhow-to-transfer-existing-git-repo-from-local-server-to-gitlab-repo-using-clish%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
git push --all
should take care of the "all branches and tags" requirement– OhleC
Nov 13 '18 at 9:44
@ohlec Agree. but I need to clone all projects into local directory(from local server) then need to transfer cloned project on gitlab server.
– SuvaP
Nov 13 '18 at 9:55