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
-
Check your current remote origin:
Run the following command to see the current remote repository:git remote -v -
Remove the current remote origin:
git remote remove origin -
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 -
Set the main branch:
Rename the current branch tomain(if it’s not alreadymain):git branch -M main -
Push to the new remote:
Push your code to the new repository:git push -uf origin main -
If your repository has multiple branches and you want to push them all:
git push --all
Git Branch Commands
-
Check available branches:
List all branches in the repository:git branch -a -
Create and switch to a new branch:
Create a new branch and switch to it:git checkout -b my-new-branch -
Switch between branches:
Switch to an existing branch:git switch new-branch