Git remote
Introduction
In this article you can learn about the basic git commands you need to work with remote repositories.
A remote repository in this context is code stored on one of the online hostings based on git.
clone
Clone another repository
$ git clone https://github.com/Project/Project.git
Cloning into 'welcome-to-git'...
remote: Enumerating objects: 9, done.
remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 9
Unpacking objects: 100% (9/9), done.
Or over SSH
$ git clone git@gitlab.com:Project/Project.git
The syntax depends on the type of authentication: password, key and so on.
remote -v
Check which remote repository the local repository is linked to
$ git remote -v
origin https://github.com/Name/name.git (fetch)
origin https://github.com/Name/name.git (push)
add origin
If you have not connected to github or to gitlab or to other services yet, you can do it with the command
git remote add origin https://git.company.com/user/projectName.git
Of course, you first have to create a project on the service's site + you need to do this in advance git init .
remote set-url
Change the attached remote repository
$ git remote set-url origin https://github.com/YourAccount/your project name.git
Check whether the attached repository has changed
$ git remote -v
origin https://github.com/YourAccount/your project name.git (fetch)
origin https://github.com/YourAccount/your project name.git (push)
push
Send new data to the remote repository
$ git push origin master
Enumerating objects: 83, done.
Counting objects: 100% (83/83), done.
Delta compression using up to 4 threads
Compressing objects: 100% (81/81), done.
Writing objects: 100% (83/83), 3.36 MiB | 3.19 MiB/s, done.
Total 83 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), done.
To https://github.com/andreiolegovichru/travel-site.git
* [new branch] master -> master
If you need to push from another branch, just write its name instead of master
git push origin some/other/branch_name
Enumerating objects: 30, done. Counting objects: 100% (30/30), done. Delta compression using up to 8 threads Compressing objects: 100% (26/26), done. Writing objects: 100% (26/26), 6.32 KiB | 6.32 MiB/s, done. Total 26 (delta 7), reused 0 (delta 0) remote: remote: To create a merge request for some/other/branch_name, visit: remote: https://gitlab.yourcompany.com/Project/Project/merge_requests/new?merge_request%5Bsource_branch%5D=some%2Fother%2Fbranch_name remote: To gitlab.ssh.com:IAM/IAM.git abcdefdc8..abcdef000 topic/qa/init_perf_test_controller -> topic/qa/init_perf_test_controller
Then follow the link
https://gitlab.yourcompany.com/Project/Project/merge_requests/new?merge_request%5Bsource_branch%5D=some%2Fother%2Fbranch_name
and make a Merge Request
pull
If the remote repository has moved ahead and you want to update your local repository with the data from the remote one
$ git pull origin master
GitHub
clone: Clone a remote repository
Create a free repository on GitHub
Protecting the main branch: blocking direct commits and a bypass for the chosen few
GitLab
Create a free repository on GitLab
Access to GitLab over ssh
Article author: Andrei Olegovich