How to use Git Remote Add Origin

Cameron McKenzie
Cameron McKenzie
4.7 هزار بار بازدید - 6 ماه پیش - Need to add a remote
Need to add a remote repository on GitHub, GitLab, or Bitbucket? Then you need to use the git remote add origin command. For a fork, use git remote add upstream.

Here's a step-by-step guide on how to add a remote repository:

GitHub:

git remote add origin https://github.com/username/repositor...
git remote add upstream https://github.com/username/repositor...

GitLab:

git remote add origin https://gitlab.com/username/repositor...
git remote add upstream https://gitlab.com/username/repositor...

git remote add upstream https://bitbucket.org/username/reposi...

Replace username with your actual username and the repository with the name of your repository.

After adding the remote repository, you can use the git push command to push your local changes to the remote repository:

git push -u origin master

This assumes you are pushing the changes to the master branch. If you are working with a different branch, like main, replace master with the name of your branch.

If you've already initialized a Git repository locally and want to connect it to a remote repository, you can use the following commands:

git remote add origin remote_repo_url
git branch -M main
git push -u origin main  # or git push -u origin master

This adds the remote repository and sets the main branch (or master) as the default branch for pushing changes.

By the way, if you run into the fatal refusing to merge unrelated histories, you will need to do a rebase to fix things up, or possibly a force, although a force isn't recommended.

The rebase to address the "fatal refusing to merge unrelated histories" error is at 12:42

0:00 Git remote add origin
2:24 Add new project to GitHub
7:34 git push -u --force
12:42 Git rebase a remote project
19:20 Git cheat method
23:18 Git, Java, Scrum, Mojo
6 ماه پیش در تاریخ 1402/11/04 منتشر شده است.
4,761 بـار بازدید شده
... بیشتر