Basic GitHub Commands (HTML version)

GitHub is a web-based hosting service for software development projects based on the Git revision control system. It provides free accounts for open-source projects as well as paid packages for private repositories.

These are the basic GitHub commands compiled by Juan Vallejo and presented at the CLAS12 software meeting on May 15, 2014.

Make Sure You're In Your Development Folder
ls cd [path]

Clone a Project to Your Machine
git clone [repository url]

Track Your Changes
git add. git add --all. git add -u.

To add all changes made throughout the repository while inside a subdirectory:
git add --all :/ git add -u :/
 * git add -u... adds only the changes from those files that have already been tracked.


 * git add -all.. tracks any new files that have been added to the project and adds any changes that have been made in the ones already tracked

Make a Snapshot of Your Code
git commit -m '[your message]' You must commit any changes you make before switching branches, or pushing to GitHub or any other remote repository.

Push to Your Branch/ Copy on Cloud
git push git push [origin / remote_repository_name] [master / name_of_remote_branch]

Switch branches locally
git checkout [branch_name] Switching branches replaces your workspace with that of another branch of your code. Even if you have code open on a text editor, this will replace those files with the ones on the new workspace.

Make a New Branch of the Current Branch
git checkout -b [branch name]

To create a new branch of any previous commit [snapshot] you might have made (Where N is the number of commits ago that you wish to use. Remove the square brackets.):
git checkout -b [branch name] HEAD~[N]

Merge a Branch to the Current Branch
git merge [branch_name]

Delete a Branch
git branch -d [branch_name]

Forced Deletion of a Branch
git branch -D [branch_name]

Store an Unfinished Tree Before Switching Branches
git stash This allows you to switch branches without committing any changes on the current one.

Resolve any conflicts when merging your code
git mergetool Opens your machine's default merge tool (usually opendiff) to help you resolve any differences between branches of your code that are too different (or may contain conflicting code) to be merged automatically by git.