2.1 KiB
Commands for Remotes
-
List all your remote repositories and show their URLs:
git remote -v -
View details about a remote repo named
origin, including all the remote branches and local tracking branches fororigin:git remote show origin -
(Pushing a new branch) You commit some files to the
dev-foobranch and try to "push" them to Github, but it fails as shown here:cmd> git checkout dev-foo cmd> git push fatal: The current branch dev-foo has no upstream branch.Explain this error.
This error occurs because the local branch
dev-foodoes not have an associated remote tracking branch. We can fix this by using the commandgit push -u origin dev-footo establish a tracking relationship. -
The command to push
dev-footooriginas a new remote branch onoriginis:git push origin dev-foo -
(Create a local tracking branch for a remote branch) The remote repository (
origin) has a branch namede2e-testthat you don't have in your local repository.
The command to create a new local branch as a copy of the remotee2e-testbranch that tracks the remote branch is:git checkout -b e2e-test origin/e2e-test -
The command to change the URL of the remote "origin" to a new URL, such as
https://hostname/newuser/new-repo-name, is:git remote set-url origin https://hostname/newuser/new-repo-nameThis situation occurs when:
- you change the name of a repo on Github
- you transfer ownership of a Github repo to someone else
- you move from Github to another hosting site, like Bitbucket
- you want to switch from the https to the ssh protocol (the remote URL is different)
-
To create a second remote repository for your local repo, the command to add a remote named "bitbucket" with the URL "https://bitbucket.org/your-username/git-commands" is:
git remote add bitbucket https://bitbucket.org/your-username/git-commands- Note: you must create an empty repo on Bitbucket. This command just adds it as a remote, it won't create the remote repo.