Github and Gitlab

Suppose you have a code repository on GitHub (or GitLab), and you want to switch it to the other platform. To achieve this, you need to update the remote origin. Follow these steps:

Switching the Remote Origin

  1. Check your current remote origin:
    Run the following command to see the current remote repository:

    git remote -v
    
  2. Remove the current remote origin:

    git remote remove origin
    
  3. Add the new remote origin:
    Replace the URL with the new repository’s URL. For example:

    git remote add origin https://gitlab-token-name:token@gitlab.com/myuser/myrepo.git
    
  4. Set the main branch:
    Rename the current branch to main (if it’s not already main):

    git branch -M main
    
  5. Push to the new remote:
    Push your code to the new repository:

    git push -uf origin main
    
  6. If your repository has multiple branches and you want to push them all:

git push --all

Git Branch Commands

  1. Check available branches:
    List all branches in the repository:

    git branch -a
    
  2. Create and switch to a new branch:
    Create a new branch and switch to it:

    git checkout -b my-new-branch
    
  3. Switch between branches:
    Switch to an existing branch:

    git switch new-branch
    

References