Skip to content

Instantly share code, notes, and snippets.

@sxflynn
Last active September 23, 2024 11:18
Show Gist options
  • Save sxflynn/3ed8f78fe9c4a115ab14857854ab7f6d to your computer and use it in GitHub Desktop.
Save sxflynn/3ed8f78fe9c4a115ab14857854ab7f6d to your computer and use it in GitHub Desktop.
How to port your GitLab repo to GitHub, step by step

Move your Gitlab repository to GitHub

Why move to GitHub?

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.

Directions

  1. cd into your existing Gitlab repository that you want to move to Github.

    • This is what mine looked like:
    cd stephen-flynn-student-code/
    
  2. 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.
  3. 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.
  4. GitHub will try to give you code on what to do next, but ignore it.

  5. 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 while git 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.

  6. 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.

  7. Go to the token settings which is found in Settings -> Developer Settings -> Personal Access Tokens -> Tokens (classic)

  8. 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.

  9. 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.
  10. 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
    
  11. 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!

Make your private repo commit history public

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.

Remove GitLab as origin

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.

@jrhurleycode
Copy link

jrhurleycode commented Dec 8, 2023

Hi Stephen! There's one more step your GitHub instructions need to actually make the commits show as public. Currently, the commits will only show for yourself for private repos. They are not public. In order to show commits publicly for private repos, go into the Github Settings > Public Profile > select "Include private contributions on my profile" under "Contributions & Activity"

@sxflynn
Copy link
Author

sxflynn commented Dec 15, 2023

Hi Stephen! There's one more step your GitHub instructions need to actually make the commits show as public. Currently, the commits will only show for yourself for private repos. They are not public. In order to show commits publicly for private repos, go into the Github Settings > Public Profile > select "Include private contributions on my profile" under "Contributions & Activity"

I appreciate your reply. I made the change in the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment