Skip to content

Lesson2b VersionControl

Katy Huff edited this page Feb 13, 2012 · 15 revisions

Version Control : Collaboration on GitHub

Back To Local Version Control - [[Forward to Python Shell and Variables | Python1-ShellAndVariables]]

github.com?

GitHub is a site where many people store their open (and closed) source code repositories. It provides tools for browsing, collaborating on and documenting code.

Setting up github at first requires [[some setup | http://help.github.com/set-up-git-redirect]].

git config : Configuring your git environment

Once you've set up your rsa keys, you need to tell github who you are. Crack open a terminal.

$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "[email protected]"

Unless your name is Firstname Lastname, please don't copy the above lines verbatim. Make the appropriate substitutions.

If you did this properly, you'll have a file in your home (~) directory that's called .gitconfig . It's contents should look like :

[user]
      name = Katy Huff
      email = [email protected]

This configuration step allows github to properly credit the authorship of changes you make in your repository. For projects with numerous authors, this is essential.

Another configuration step for some will be to set their favorite text editor as git's text editor of choice. This is optional, since vi is usually the default, but can be done with the following command (if you like nano for example):

$ git config --global core.editor nano

git remote : Steps for Forking a Repository

A key step to interacting with an online repository that you have forked is adding the original as a remote repository. By adding the remote repository, you inform git of a new option for fetching updates and pushing commits.

The git remote command allows you to add, name, list, and delete repositories such as the original one upstream from your fork, others that may be parallel to your fork, and so on.

Exercise : Fork Our GitHub Repository

While you probably already have a copy of the PyTrieste repository, GitHub doesn't know about it yet. You'll need to tell github you want to have an official fork of this repository.

Step 1 : Go to our [[repository | https://github.com/thehackerwithin/PyTrieste/]] from your browser, and click on the Fork button. Choose to fork it to your username rather than any organizations.

Step 2 : Clone it. From your terminal :

$ git clone [email protected]:username/PyTrieste.git
$ cd PyTrieste

Step 3 :

$ git remote add upstream git://github.com/thehackerwithin/PyTrieste.git
$ git remote -v
origin  [email protected]:username/PyTrieste.git (fetch)
origin  [email protected]:username/PyTrieste.git (push)
upstream        git://github.com/thehackerwithin/PyTrieste.git (fetch)
upstream        git://github.com/thehackerwithin/PyTrieste.git (push)

git fetch : Fetching the contents of a remote

Now that you have alerted your repository to the presence of others, it is able to pull in updates from those repositories. In this case, if you want your master branch to track updates in the original PyTrieste repository, you simply git fetch that repository into the master branch of your current repository.

The fetch command alone merely pulls down information recent changes from the original master (upstream) repository. By itself, the fetch command does not change your local working copy. To update your local working copy to include recent changes in the original (upstream) repository, it is necessary to also merge.

git merge : Merging the contents of a remote

To incorporate upstream changes from the original master repository (in this case thehackerwithin/PyTrieste) into your local working copy, you must both fetch and merge. The process of merging may result in conflicts, so pay attention. This is where version control is both at its most powerful and its most complicated.

Exercise : Fetch and Merge the Contents of Our GitHub Repository

Step 1 : Fetch it

$ git fetch upstream

Step 2 : Make certain you are in the master branch and merge the upstreeam master branch into your master branch

$ git checkout master
$ git merge upstream\master

Step 3 : Check out what happened by browsing the directory.

git pull : Pull = Fetch + Merge

The command git pull is the same as executing git fetch followed by git merge. Though this is shorter in simple cases, it is not recommened for cases in which there are many branches to consider.

Dealing with Conflicts

This is the trickiest part of version control.

Imagine the following situation :

Clone this wiki locally