Basic Instructions for Git and Github


See also this video that Titus made about merging

1. Cloning a repository.

Cloning a repository (from github or anywhere else) makes a local copy of the contents of that repository.

To clone a repository, locate your HTTPS repository URL; it should look something like this:

where ‘ctb’ is your username instead, and ‘cse491-serverz’ is whatever repository you’re trying to clone locally.

note: it must end in .git.

Then do ‘git clone $URL’, replacing $URL with the repository URL. This will create a directory named after the repository. You can rename this directory to whatever you want, move it around, etc; it’s entirely self-contained.

You can now edit files and do whatever you want in this repo.

2. Committing changes

Do a ‘git status’ to see what git thinks has been changed.

‘git diff’ will show the differences between the last commit and the current changes.

The command:

git commit -am "my changes"

will commit all the changes to the repository. A ‘git status’ immediately afterwards should show no changes.

‘git log’ will show you a list of commits.

3. Pushing changes to github

The command:

git push origin master

will push all changes in the master branch (the default one) to the remote location called ‘origin’, which, by default, is wherever you cloned things from.

Here, ‘master’ is the branch. So if you have a branch, say, ‘other’, you can do:

git push origin other:other

You can use ‘git remote’ to add, remove, edit, and otherwise mess with your various location aliases (e.g. ‘origin’).

4. Creating new branches, and switching branches

To create a new branch called ‘other’, you can do:

git checkout -b other

This will copy your current branch into a new branch called ‘other’.

You can switch to an existing branch by doing:

git checkout other

and you can see existing branches with:

git branch

5. Pushing changes to github with different branch names.

There’s no reason you have to use the same branch names in your local repo as in your github repo. For example, if you do:

git push origin master:other

this will push the contents of your local master branch into the remote branch named ‘other’.

Edit this document!

This file can be edited directly through the Web. Anyone can update and fix errors in this document with few clicks -- no downloads needed.

  1. Go to Basic Instructions for Git and Github on GitHub.
  2. Edit files using GitHub's text editor in your web browser (see the 'Edit' tab on the top right of the file)
  3. Fill in the Commit message text box at the bottom of the page describing why you made the changes. Press the Propose file change button next to it when done.
  4. Then click Send a pull request.
  5. Your changes are now queued for review under the project's Pull requests tab on GitHub!

For an introduction to the documentation format please see the reST primer.