Only days ago I start using Git. So, naturally I am far from an expert. Still I think someone could find this useful. Briefly, this is what you do on the “master” computer to get started:
- Download and install Git (eg. adding the necessary path to .bashrc).
- Download and install the GUI wrapper GitX for OS X 10.5+.
- Introduce yourself to Git.
- Create a folder for the project and from within that folder initialize Git.
- Create the .ignore file to avoid Git caring about the build folder (and others Git should disregard).
- Add all the project files, which includes the hidden .ignore file.
- Commit the added files to the log and write a good multi-line commit message (short title followed by listed details).
Now, from the “other” computer, repeat steps 1-3 above before continuing:
- Use git to pull down the entire repository. Do this in terminal from the folder that should contain the project folder.
- Open GitX to verify that the repository is in fact intact (simply open the project folder).
- Continue developing the project as normal.
- The changes needs to be staged (comitted) before they can be pulled by another computer.
Changes made on one computer is basically pulled to the other using the same steps as above. So every time you switch to your other computer, you go through those 4 steps. Easy. More details follow.
Installing Git
Download Git from the main site: http://code.google.com/p/git-osx-installer/downloads/list?can=3 If you are not sure, go for the installer and make sure it is targeted for your platform (Intel vs. PPC). After the normal installation you should be able to run Git. Open the Terminal and type in:
which git
This shows you where Git was installed, which also means it is ready for use. If nothing shows up, you might need to add the path to .bash_profile, in a similar fashion as below. However, when connecting using SSH, only the .bashrc file is actually loaded, so you should also make sure the path is there as well. This can easily be done by executing this in terminal:
echo export PATH=/usr/local/git/bin/:$PATH >> ~/.bashrc
This will create the file if needed, or append the path to the existing .bashrc file in your home directory. Now download and install GitX from http://gitx.frim.nl/ – a very nice GUI rapper for Git on OS X 10.5+.
You are now ready to actually start using Git.
Initial Cloning
To get a clean copy of a project on the LAN, you need the local IP address (eg. 10.0.1.4) or the alias (imac.local) of the computer hosting the project. You can connect using either SSH (enable remote login) or HTTP (enable web sharing). However, in this post I will only use SSH.
To get the initial project from another computer, you run the git clone command from within the folder that should contain the cloned project (you can move it later). Type the following at the command line:
git clone ssh://home@imac.local/~/Projects/TheOne
This copies the entire project folder (including the hidden .git repository) to the current destination. In the example above I used ssh to connect to the local computer imac.local. The home@ informs git to connect using home as the user name on the remote system. Following the server name are ~/Projects/TheOne which means to access Projects contained in the Home folder of the specified user which contains the project called TheOne.
Having cloned the project, you can now inspect the project history using GitX. Launch GitX (if needed click File > Open) and select the project folder (no need to expand or enter it). Nice.
Get the latest changes
To update your project with the latest changes, you simply pull the changes from the other computer:
git pull ssh://away@macbp.local/~/Projects/TheOne master
The added word master lets git know that you want everything, not just a single branch. When you have changed some files on your laptop, you could push the changes back to the other computer. However, this is not a good idea if the files are checked out on the other end as your changes could get lost.
“By the way, behind the scenes, a pull is simply a fetch followed by git merge; recall the latter merges a given commit into the working directory.” (from GitMagic)
Until I get more familiar with Git I will simply pull the changes from the most current computer as needed.
GitX Contributions and Further Reading
You can easily download the source for GitX and contribute to the project by running:
git clone git://github.com/pieter/gitx.git
Read more about contributions from the contribution section of their own web page.
Read more about using Git with remotes: http://progit.org/book/ch2-5.html
Posted by Johan