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.
- Login/Create a GitHub account, install git on your system
- Go to the repository you’re forking
- Hit the big fork button
[Sometimes if you’re new, GitHub will give you some help here. If you like those instructions better, use them]
- Copy your SSH repository link
- 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.
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 email@example.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'
# Check to see if there are any changes to the repository
# 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
# 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
git push origin master