Skip to content
kennethklee edited this page Mar 29, 2013 · 3 revisions

Using Git

This is a page on basic usage of git.

Clone

git clone <repo url>

Note: You should probably delete the master branch, so as not to overwrite it or push changes to it.

Example

git clone [email protected]:annsonn/saboteur.git

Listing branches

git branch -a

Switch branches

git checkout <branch name>

Example

Switching to the remote master branch: git checkout origin/master

Switching to a local branch: git checkout feature/someFeature

Branch

Create the branch. You must currently be in the branch you want to clone from. This works with remote branches as well.

git checkout -b <branch name> The -b tells git to create a new branch.

Note: Prefix the branch name with feature/ or fix/ to group it to fixes or features. For organization sake.

Example

git checkout -b fix/someFix

Rebase branch

When your base branch has changes, you'll want those changes.

git fetch <remote name>

Where <remote name> is the name of your remote repository, typically origin.

git rebase

Rebase will roll back to when you first created the branch, update your base, then replay your changes. If there is a conflict, edit the conflicted files to resolve them. Add the files using git add, then continue your rebase with git rebase --continue. You'll then want to force push your branch to remote.

Commit your changes locally

You may need to add new files that are not included into your local repository. Omit if no new files.

git add -A

Save your changes with a change message.

git commit -am '<message here>'

Save branch to remote

This will save all your committed changes to a remote repository (effectively saving your changes on a server).

git push -u <remote name> <branch name>

Where is the name of the remote repo, typically origin. The -u tells git to default pull requests to the remote branch.

Delete branch

You've created a branch you weren't supposed to. So delete it.

git branch -d <branch name>

Github allows you to delete a remote branch after merging a pull request. But you may want to delete it manually.

git push <remote name> :<branch name> Make sure you include the : to signal a delete.

Purge old remote branches

git remote prune <remote name>

Remember that is typically origin