Skip to content

Pam’s Intro to Git with GitHub

Last month, during Julython, PhillyPUG organizer Dana Bauer invited me to give a couple git tutorials as part of our goal to get more Pythonistas into FOSS. Then at a hack this past weekend, I started on a team only to discover my teammates had never used GitHub or git. So here’s a quick intro.

I’ve also heard people enjoy GitHub/Codeschool’s TryGit environment. However, that and most other git tutorials assume you start with a blank project — people new to git are rarely approaching it from this angle. Instead, here’s another scenario:

You want to fork someone’s repository to collaborate and participate in a hack 

Let’s use @pydanny’s that as our example repository. Why? Because it’s silly.

  1. Login/Create a GitHub account, install git on your system
  2. Go to the repository you’re forking
  3. Hit the big fork button
    forking
    [Sometimes if you’re new, GitHub will give you some help here. If you like those instructions better, use them]
  4. Copy your SSH repository link
    get-repo-url
  5. In your shell, type git clone [paste your link] and hit enter. Git will create a copy of the repository with the appropriate version control information AND the correct origin remote.

Someone else wants to add you to the repository for a project to collaborate

Follow the steps above, except instead of forking, your friend needs to add you as a collaborator. When you refresh your view of the repository, you’ll have access to an SSH link. Perform steps 4 & 5, and the repository is yours.

Admin Screen:

add-collab-1

Add collaborators:

add-collab-2

Once you have the project on your machine, there are just a few major commands to know. Here’s an overview gist with the commands above, plus some more.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Gimme someone else's repo to check out!
git clone git://github.com/pydanny/that.git

# Gimme that forked repo!
git clone git@github.com:YOUR_USERNAME/that.git

# Go into that repo
# When you cloned, git created a directory with the
# same name as the repository. cd is 'change directory'
cd that

# Check to see if there are any changes to the repository
git status

# Add files or add changed files to commit staging
git add FILE_NAME

# Add e'rything in the directory
git add .

# Change your mind, undo any local changes
git reset --hard

# If you've added files/added changed files, commit them
git commit
# This takes you to a screen to add your commit message. You MUST have a commit message

# Commit and grab any and all changed files (does not add files)
git commit -a

# Commit, grab everything, and provide the commit message inline
git commit -am "A descriptive commit!"

# Go get changes to your repository
# Then, merge the changes into your local
git pull origin BRANCH
# For beginners, often
git pull origin master

# Send up your commits and changed files
git push origin BRANCH
# Usually
git push origin master

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.