One nice spin-off from using version control is that it's easy to backup and sync changes. Once everything's set up, we just pull before editing, and then commit and push when we're done. This enables multiple users (or the same person on multiple computers) to work on the project. Changes are merged automatically when possible, or highlighted for the user when not.
client> cd proj/ # we'll resume work on proj. client> git pull # make sure we have the latest changes. client> vim file.tex # make some edits. client> git commit -a # tell git about those edits. client> git push # push them to the server.
We deliberately skipped a step. Here's how to set it up: we'll create a repository on our server (ant), then tell our client (kiwi) about the server.
ant> cd ~/gitrepos/ # common place to store all repos. ant> mkdir proj # store this particular project in its own repo. ant> cd proj/ ant> git init --bare # the bare means we won't develop in here directly.
Now we'll tell our client about the server. The name origin is git's default name for a remote repository. The name master is the default branch on our local machine — later, you can use multiple branches when trying out experimental file changes (for example). Don't worry too much about these names right now.
kiwi> git remote add origin ant:gitrepos/proj/ # add the link to ant. kiwi> git push origin master # push changes to ant.
We can develop with multiple computers (or people). Let's introduce another client, kakapo. First, we'll make some more changes on ant.
kiwi> vim file.tex # make some more changes. kiwi> git commit -a # tell git about these changes. kiwi> git push origin master # push the latest commit to ant.
# Create a folder called proj/ on kakapo and pull the changes. kakapo> git clone ant:gitrepos/proj/
kakapo> cd proj/ kakapo> vim file.tex # make some edits on kakapo. kakapo> git commit -a # tell git about the changes. they remain local for now. kakapo> git push # push them to ant:gitrepos.
We uploaded the changes to the server, but our original client kiwi won't know about them yet. Let's pull the changes from the server down to kiwi.
kiwi> cd proj/ kiwi> git pull origin master # fetch the latest changes from kakapo.