Skip to content

Git Commands Cheatsheet

Sam Perry edited this page Nov 26, 2016 · 1 revision

Basic commands

Download a repo from the URL and place it in a folder inside the current directory

git clone URL

All further commands will be executed from within the directory downloaded...

This is setting up a "remote" (the github repo where everyone's code will be uploaded and stored) the new remote is named locally as "origin" (this is the standard name for the default repo)

git remote add origin URL

Branching

You will need to set up a "branch" of your own which you will write on. Each of us has a branch called 'name-dev'. When we've written some code that is ready for use we will then merge our code from these branches to the master branch.

List all branches that exist in this repo

git branch -a

Create a new branch with the name provided

git checkout -b NameOfBranch

To switch to another branch and see what other people are doing just check out their branch.

git checkout NameOfBranch

Adding files, commiting them and pushing to the github repo

When you have made changes to files/added new files etc... you will want to save these changes and send them to the public repo that we can all see.

"Stages" a new file ready to be commited to the branch you are on (hopefully your branch)

git add path/to/NewFile.txt

Shows the status of the project.

git status

If you had just added the new file it would look similar to this:

On branch sam-dev
Your branch is up-to-date with 'origin/sam-dev'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   NewFile.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        OtherFile.txt

Commiting creates a snapshot of the current state of the project based on the files that you have added to the repo

git commit -m "Added functionality A"

Having made a new commit, you are ready to push your branch to the repo to back it up. This is done for the first time with:

git push -u origin

That sets the local repo to push all the future commits to "origin" when you simply run:

git push

Before any commit it's usually a good idea to run:

git add -u
git status

This adds any changes to files that were commited previously, then shows you what files have been changed.

Clone this wiki locally