A remote repository is just another copy of the git repository to which yours is linked. It can be on the same computer in a different file location, on a different computer, for example a departmental server, on the laptop of a collaborator who is also working with you or on a git hosting service.
The main sites are
github
bitbucket
gitlab
You create a new repository by clicking the green "New Repository", give it a name, and optionally a description, licence, gitignore and README.
Once the repository has been set up click on the Clone
button and copy the code required to clne the repository:
git clone https://github.com/<your-git-username>/<your-respository>.git
When we cloned the repository earlier that was a read only operation at the remote end. Now we are going to write to the remote repository we need to be authorised to do it. To avoid having to repeatedly put in the passowrd we'll ask git to cache the credentials
git config credential.helper cache
Alternatively you can use ssh keys to manage github authentication.
git remote
informs you which remotes are set up for your local copy of the repository:
git remote
origin
and if you add the -v
flag gives the full location of your remote repositories:
git remote -v
origin https://github.com/christopheredsall/workshop-test.git (fetch)
origin https://github.com/christopheredsall/workshop-test.git (push)
Fetch copies a remote branch to your local machine, but does not merge it with your local branch.
git fetch
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
Unpacking objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
From https://github.com/christopheredsall/workshop-test
582e532..765c3bb master -> origin/master
If you want to fetch and merge a remote then git pull
does a git fetch
followed by a git merge
git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working directory clean
git pull
Updating 582e532..765c3bb
Fast-forward
file2.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 file2.md
If we have made changes to our local repository we want to get them in to the remote. We use the git push
command to do that. The first time through it will give you a warning about how the default behavour has changed. You can do what it suggests to get rid of the warning next time
git config --global push.default simple
git push
Username for 'https://github.com': christopheredsall
Password for 'https://christopheredsall@github.com':
Counting objects: 3, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 320 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/christopheredsall/workshop-test.git
765c3bb..e031f0f master -> master