Working With Git Remotes
These are my notes on Git remotes.
To help or collaborate with others on a project, you have to learn about Git remotes. These are remote repositories hosted somewhere else. The repository could be yours that someone else is helping with or you could be helping someone with their repository. You could have many repositories on your machine. The goal is to help and this involves sending and receiving data from the specified repository.
Seeing Your Remotes
To see the remote servers you have, you run the command:
Git remote
It will list the remotes you have configured to work with. If you have cloned a remote, it will show that in the name. You can see the web addresses that are associated with the remote repository by using the command:
Git remote -v
Adding Repositories
The clone command will add a remote for you. However, you can use it to name the remote something to your liking.
Git remote add [nickname] [address]
This allows you to use the nickname to refer to the repository address.
Git remote add geo [web address]
Then, when I want to download everything to my machine from that remote I use:
Git fetch geo
The git fetch command is new, so let me explain. If you have access to a remote, you just use the fetch command to pull new information from it to your local machine.
Git fetch origin fetches any new work since you cloned it or last fetched from it. It does not merge with any of your previous work.
If you want to fetch and merge the remote with your current branch, then you will want to use:
Git pull
Many people do this. It merges automatically.
Pushing To Remotes
When you push a remote, you are sending your code or other work to the remote repository. You will want to do this every so often anyway. It is your way to save and let others see where the project is currently. You use:
Git push [remote] [branch]
That will send a particular branch of your project to the server.
However, if you want to send your master branch to the remote server then use:
Git push origin master
This only works if you cloned from a server you have access to and no one else has pushed to the server since.
Seeing Your Remotes
You can inspect any of your remotes to get information about it.
Git remote show [address]
It will show you all sorts of information like the web address and the tracking branch information. It will show you all the remote references as well. If the remote repository is more complex, with a lot of users for example, then [git remote show] will give you a lot more data.
Renaming Remotes
If you want to change the nickname for a remote, it is simple to do.
Git remote rename geo geometry
That changes the nickname from [geo] to [geometry]. You can check to make sure it changed to the correct name by running the remote command again.
Git remote
It will show you the server and nickname for it.
You can also just remove a remote. You might do this if you no longer want to work on it.
Git remote remove geometry
Git remote
You will see an updated list of your servers and see the [geometry] server is gone.