If you are a coding bootcamp student that has been building projects and solving exercises in a private GitLab repository that is controlled by another organization, then you might want to move your work to GitHub to preserve what you have done and learned, and make your work more visible to other developers in the community, and employers.
The GitHub profile is a great way to market yourself as a developer. You can pin repos to the top that you want to highlight to the community. It also has data visualizations on your contribution history to repo projects. Fortunately, if you have been making contributions to private repos in GitLab, all of your commit history will transfer to this graph.
-
cd
into your existing Gitlab repository that you want to move to Github.- This is what mine looked like:
cd stephen-flynn-student-code/
-
Create a GitHub account if you already don't have one.
- Make sure sure you used the same email that you used for your Gitlab account. If you used a different email, add your Gitlab email to your GitHub account as a secondary email.
-
Create a new empty repository in GitHub.
- Give it a descriptive name that will match the Gitlab repo
- In my case, I named it
techelevator-exercises
- I set mine to
private
- Do not click
Add a README file
- Do not add a
.gitignore
since your old repo should have one. - License: Choose none for now, you can change that later.
-
GitHub will try to give you code on what to do next, but ignore it.
-
Go back to the Terminal, assuming you did
cd
into your repo, and enter the below code. This will add GitHub as a secondary remote whilegit push
continues to default to your current Gitlab repo.git remote add github https://git-----.com/sxflynn/techelevator-exercises.git git push github main
Replace my GitHub repo URL with yours.
-
When you hit enter, GitHub will try to authenticate you. Enter your email/username and when it asks for your a password, you will give it a token instead of your password.
-
Go to the token settings which is found in Settings -> Developer Settings -> Personal Access Tokens -> Tokens (classic)
-
Click `Generate New Token (Classic)
- Note: Type something like
github terminal
- Expiration: Set it for a whole year, if possible. Do not set 'no expiration'
- Select scopes: Click on the
repo
checkbox to select all. All of the following should be checked:
☑️ repo Full control of private repositories ☑️ repo:status Access commit status ☑️ repo_deployment Access deployment status ☑️ public_repo Access public repositories ☑️ repo:invite Access repository invitations ☑️ security_events Read and write security events You do not need to select the rest of them.
- Note: Type something like
-
Copy the token they just gave you. Mine looked something like this:
ghp_P---H05nM----------w3Lf2fUSbCz---BX-
- Save it in a safe place because you will not be able to see that token again.
-
Go back to the terminal and paste in that token as your password. Your entire GitLab repo should now upload to your new GitHub repo. My code looked like this:
Enumerating objects: 5346, done. Counting objects: 100% (5346/5346), done. Delta compression using up to 8 threads Compressing objects: 100% (2580/2580), done. Writing objects: 100% (5346/5346), 32.86 MiB | 2.83 MiB/s, done. Total 5346 (delta 1783), reused 5189 (delta 1678), pack-reused 0 remote: Resolving deltas: 100% (1783/1783), done. To https://github.com/sxflynn/techelevator-exercises.git * [new branch] main -> main
-
Check your GitHub profile and now you should see a whole bunch of contribution history that wasn't there before. Now your GitHub profile more accuracutely reflects all the work you've been doing in your previous GitLab!
Finally, you may have to set your commit history in private repositories to public. Go to Settings -> Public Profile and click on Include private contributions on my profile
otherwise your commit history will remain unaffected.
Thanks to @jrhurleycode for that tip.
After your coding bootcamp is over and you still want to work on your repo, but you no longer need to push code to your GitLab repo, follow these steps to sever the link to Gitlab and make Github your default origin
.
Check your list of remotes
git remote -v
You should see your old GitLab repo listed alongside Github.
Remove your origin
linked to GitLab
git remote remove origin
Rename your github
remote to origin
git remote rename github origin
Now when you do git push
it will default to pushing to your github remote.
I appreciate your reply. I made the change in the document.