Git Workflows

These are chains of commands that you’ll commonly find use of in the course of contributing to our projects.  It is recommended that you are familiar with the material on the “Git Intro” page.  The following diagram will be very useful:

If you are still having trouble visualizing things, you might find the guide here http://marklodato.github.com/visual-git-guide/index-en.html better to sate your appetite.  (Terminology translation:  ”History” = local repo, “Stage” = index, “Working Directory” = workspace)

Basic Workflow

You’ll use these commands every time you work on OLPC.  No exceptions!  (Or, if you do find an exception, please tell me so I can learn your super-secret-git-kung-fu)

# Get the most recent version of the project
# This picks up all changes that other people may have made
git fetch upstream

# Attempt to merge all fetched changes with your local files
# If there are any conflicts, you'll be prompted to resolve them
git merge upstream/master
# If you get a merge 'conflict', then PANIC
# After PANIC, see the section at bottom on solving merge conflict

# while (editing):
   # Add a snapshot of the specified file to the index
   git add <file>

# Check your added changes by comparing index VS local repo
git diff --cached

# Saves all changes in the index as a single commit
# NOTE: These commits reside in your local repository
git commit -m "<description of what you have committed>"

# Submit the contents of your local repo to your remote repo
# Your remote repo is default named 'origin'
git push origin master

# Now go online to your Github account.
# Navigate to your project repo.
# Punch "Pull Request" next to "Fork", "Unwatch", etc at the top.
# You should be good to just hit okay.

Special situations and mistakes may require additional commands listed under the ‘Advanced’ section.  Otherwise, if you are way in over your head with a problem, let fly with Google.  You can also contact me directly, but ONLY if you include “OLPC” somewhere in the subject line: djmailhot[AT]gmail.com.  (Think I’m kidding about that subject line?  Just try me… )

 

Specific & Advanced Commands


Pull most recent changes

# This downloads the most recent version of the project
# 'upstream' is the name of UWOlpc's remote repo
# This will put everyone's project additions onto your computer.
git fetch upstream
git merge upstream/master

Make Changes

# Add a snapshot of the specified file to the index
git add <file>
# TIP: A more informative and interactive add (with learning curve)
git add --interactive
# NOTE: If a file is 'added', then you edit it, you must 'add' again

Commit changes

# Check your added changes by comparing index VS local repo
git diff --cached
# Saves all changes in the index as a single commit
git commit -m "<description of what you have committed>"
# TIP: A more informative and interactive commit (with learning curve)
git commit --interactive
# TIP: Amend your last commit with any additional changes in the index
git commit --amend
# TIP: You can see your commit history with the log tool
git log

Submit changes

# Submit the contents of your local repo to your remote repo
# Your remote repo is default named 'origin'
git push origin master

# Now go online to your Github account.
# Navigate to your project repo.
# Punch "Pull Request" next to "Fork", "Unwatch", etc at the top.
# You should be good to just hit okay.

Solving a merge conflict

One day, you’ll come across a merge conflict. After panicking for little bit, you’ll realize there’s nothing much to worry about. First off, Git will yell at you. Second off, think about whether you actually want to merge the new with the old, or simply want all of the new. Third off, if you want to fix your conflict , it’s easy. Your files will be populated with sections like below:

        def goodletter(self, letter):
                temp = display_output.word
                a = []
<<<<<<< HEAD                 
                bunnies = 'jump jump poof!'                 
                print bunnies                 
                if letter in bunnies:                         
                   a.append(bunnies) 
=======                 
                for n in range (0, len(temp)):                         
                   if letter == temp[n]:                                 
                      a.append(n) 
>>>>>>> FETCH_HEAD
                display_output.accept(self, letter, a)

The ‘HEAD’ section is what you have locally. The ‘FETCH_HEAD’ section (or maybe ‘upstream/master’?) is the upstream code that conflicts with your local file. So just manually edit the file so that the code works (and delete the section dividers too). You can find all of the files you need to edit with ‘git diff’.

        def goodletter(self, letter):
                temp = display_output.word
                a = []
                bunnies = 'jump jump poof!'
                print bunnies
                for n in range (0, len(temp)):
                        if letter == temp[n]:
                                a.append(n)
                display_output.accept(self, letter, a)

Tadaaa! All done! Now ‘add’, ‘commit’, and ‘merge’ again to make sure there is no conflict.

2 thoughts on “Git Workflows

  1. Pingback: ELBLGOGDEPATRICIA.COM » You want to get to be a book reviewer.

  2. When someone writes an article he/she keeps the idea of a user in his/her mind that how a user can understand it.
    Thus that’s why this paragraph is outstdanding.

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>