working with remotes

Posted in GIT by

GIT is distributed. Every person with git installed can serve as client and as server. Working with remotes is very important, because otherwise you must do all work alone.

Add remote servers.

If you started a fresh GIT repo on your local pc, you will prolly want to push it to a server. In order to save yourself typing, you add a remote server once and afterwards call it by its name.

git remote add servername https://url/to/remote/repo.git

If you want to set a specific branch add -t branchname before the URL. -m master can be useful too. If it is your primary remote server, you should name it origin.

Push to remote servers

You have your work done. And made your commit local. It is time to push your work to the remote server. This is pretty fast, because only the changes are transferred, and they are compressed too. If you did not name your remote server * origin", then use your used name instead. Of course you are not restricted to master here. Change it, if needed.

git push origin master

Fetch from a remote

Fetching will not change your files, it will only add files. It is very easy and you can not do anything wrong. Again, you can change origin to the name you used or even use a url/to/a/repo.

git fetch origin

Pull from a remote

Pulling is dangerous, but since you use GIT, you can always go back. Pull will merge the project of a remote repo with your local one. If you put a branch name behind the repo name, you can pull (works with fetch too) from a specific branch.

git pull origin

Where to go from here?

Git includes a documentation. Just type git help in the command line and it will show you a HTML with it. If you need help to a specific git command, use git help commandname.

If you have questions or think something can be written better, please leave a short note.

Published at , Updated at 2013-03-02

next: Reset: Recover your mistakes prev: Introduction to GIT