Git

From DesigningPatterns

Jump to: navigation, search

Contents

Background

Git is a distributed version control system. It is used in GitHub.

Installation

yum install git

A graphical diff and merge tool is a necessity. Designing Patterns uses xxdiff for this right now.

Usage

Designing Patterns does not use git for its projects, but it sometimes is necessary to patch an external project that uses git (on github, for instance). These instructions will walk through submitting a patch.

Install git. Run:

git config --global user.email name@domain.com
git config --global user.name "Your Name"

in order to configure git.

If using github, then a git repository can be created by forking an existing project. The new repository page will show the public repository URL (can be used by anyone for a read-only view of the code) and a private repository URL (can be used to change the repository). Use the desired repository with the git clone command in order to download a copy of the repository:

git clone git@github.com:DesigningPatterns/hanna.git

This will create a hanna directory with the repository's code. Make any necessary changes and commit the code back into your local repository with:

git commit -a

In order to commit the changes to the remote github repository, do:

git push

When your patch is ready to be submitted to the main project repository, click on the "Pull Request" button on the repository page (which basically will send a message to interested parties about your code).

If you later need to pull changes from the "master" repository into your forked repository (i.e., "rebase" your repository), clone your forked repository and run:

git pull PUBLIC_MASTER_REPO_CLONE_URL refs/heads/master:refs/heads/origin
git push

github uses a key pair authentication system, which must be satisfied in order to clone from a private repository or in order to push changes to a repository. This tutorial on github authentication and this tutorial on multiple github accounts are good references. The first tutorial did not contain complete information for me, unfortunately. In order to get github working, I:

  • Copied my public key into my github account maintenance page (I already had one from configuring ssh; a new key pair can be created with ssh-keygen -t rsa).

If you create a different key pair than your default key pair, you need to tell git about it:

  • Add this to ~/.ssh/config:
Host github
  HostName github.com
  User git
  IdentityFile /home/tony/.ssh/git_hub2

After doing this, I got git to use the key pair by replacing github.com in the clone command with github. For example:

git clone git@github:DesigningPatterns/hanna.git

References

Personal tools