Skip to content
Manko10 edited this page Sep 27, 2011 · 8 revisions

This is a general introduction to Git and how to use it on the command line. If you know how to use the command line (if you've worked with adb already, you most likely know how to use the console), this is the preferred way. All other users might use a graphical tool. See Home for a list of some of them.

The installation process might look tedious but it has to be done only once. Usage of Git is much simpler.

Installation

First you need to install Git. Depending on your operating system, the process differs slightly.

Linux

Use your package manager to install the package git or git-core (whatever it is called on your distribution). Gentoo users might run

sudo emerge -av git

Ubuntu users might need to run

sudo apt-get install git-core

If unsure, what to do, just google for install git <your distribution>

Windows

Windows users have to install msysgit. Just download the package and run the installer.

If you like, you can check Git Bash here under Context menu entries which will add an entry in the Explorer context menu to open a Git command window for the current directory. Leave all other settings as-is. The installer will install all needed binaries and a program called Git Bash. This is the command line window you will use. If you want to use Git from your normal cmd DOS prompt, you have to add C:\Program Files (x86)\Git\bin to your path environment variable (installation path might differ, check that first). To do this, right click on Computer and then on Properties. Now click on Advanced system settings and eventually on Environment Variables. Locate the entry path, click Edit, add a semicolon and the path above. Confirm everything with OK. You should now get the version number of your Git installation when you enter

git --version

into a DOS prompt. Note: that this is not the recommended way. Better use the Git Bash.

OS X

As a Mac OS X user you can either download git-osx-installer (see the Wiki there or this tutorial for installation instructions) or install git-core via Macports. Yes, OS X is the only crappy system which makes it always hard to install open source software.

For more information about installation in general (and for installation of Macports), read the entry in the Git book.

Generate SSH key

After installation has been finished, we need to generate an SSH key. This is the key used for accessing your GitHub repository. Open an terminal window on Linux/OS X or the Git Bash on Windows. Run the following command:

ssh-keygen

This will ask you for a path of a file while suggesting a default one. Remember the default path and hit enter. In the next step you can enter a password to encrypt your key. Leave blank for no password. Hit enter, type in the same password again (or leave blank if no password) and the hit enter once more.

Now open the directory (!) which contains the file I told you to remember in your file manager (Finder on OS X, Explorer on Windows). Windows users need to replace /c with C: (or which driver letter you use) and all forward slashes / with backlashes \. Copy the contents of the file id_rsa.pub (not id_rsa!) to the clipboard, click on Account settings here on GitHub, then on SSH Public Keys, set a title of your choice and paste your key into the Key field. Hit OK and you're done. You have now read and write access to your repository via Git.

Warning! Make sure you keep the contents of id_rsa secret. id_rsa.pub may be known by anyone, but id_rsa is highly confidential.

How to get started

Once you've set up Git, you have to open a terminal window (or the Git Bash on Windows). From here on everything is exactly the same on all three platforms.

First of all change to the directory where you want to have your Git repository:

cd your/directory/of/choice

Then enter

git clone [email protected]:Username/InsertCoin-Docs.git

(replace Username with your username). If you have encrypted your SSH key, you have to enter the password now. Otherwise Git should directly start cloning the repository.

If you get this warning (make sure the RSA key fingerprint is the same)

The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?

type yes and hit enter (this message shouldn't appear again).

Once Git has finished, you should see a directory InsertCoin-Docs when entering the command

ls

(note: always hit enter to confirm a command). Change to this directory

cd InsertCoin-Docs

This is your working copy of the repository. Now you can start editing the files. Of course you don't have to do this from the command line. You can use any editor you want. You only need the command line to commit changes, push them to your GitHub fork and keep your copy fresh.

Last but not least you need to add the origin repository to be able to keep your copy fresh. To do this, run the following command:

git remote add upstream git://github.com/Manko10/InsertCoin-Docs.git

Committing files

After editing your files you need to commit them. Committing means that you tell Git to track what you've done to the files. To commit make sure you're inside your repository (switch to the directory with cd as shown above).

Now you need to tell Git which files to track. Add them by entering

git add filename

Replace filename with the name of the file you want to add to Git. If you have more than one file, you can specify them all at once, separated by spaces. If one of your file names contains spaces, you have enclose it with quotes ("file name").

If you don't want to specify each file manually, you can also tell Git to add all new or modified files by just running the command

git add -A

(it has to be an uppercase A). Once the files are added, you can commit them:

git commit -m "Some message"

Replace Some message with a more meaningful description, confirm the command with enter and you're done. Git has tracked the changes.

Push to your GitHub repository

Committing things does not publish anything. You need to push the changes in order to see them in your GitHub repo. To push your commits to GitHub run

git push

If you have set a password for your key you need to enter it now. Then Git pushes all your commits to your GitHub fork. Be aware, that only committed modifications are pushed.

Refresh your copy

Your GitHub fork doesn't refresh anything automatically but of course development goes on and the upstream repository might (and most likely will change). To pull in the current revisions run

git pull upstream master

This will pull in everything from the main repository (not from your fork) to your local working copy. To update your GitHub copy as well push the freshly pulled changes as shown above.

Send a Pull Request

If you have done modifications you want to appear in the main repo and on the staging website, send a Pull Request by clicking the Pull Request button here on GitHub. Write some informative description and we'll see if we can merge your modifications. Be prepared for some further discussion in the discussion thread for your Pull Request.

Be aware that we can only merge changes you have pushed to your GitHub repo. Revisions which only exist in your local copy are only visible to you.

If you have sent a pull request but then perceive you forgot something, just make your new modifications, commit and push as usual. As long as we haven't merged anything, your new changes will be added to the open Pull Request automatically.