Git and GitHub Notes

Initial Setup

$ git config –global user.name “Jon Matthews”
$ git config –global user.email joncarlmatthews@gmail.com
$ ssh-keygen -t rsa -C “joncarlmatthews@gmail.com”
$ cat ~/.ssh/id_rsa.pub

https://github.com/settings/ssh

How to create a branch

Create it locally:
$ git branch my-new-branch

Switch to the branch
$ git checkout my-new-branch

Push the branch back to the remote host
$ git push origin my-new-branch

How to delete a branch

To delete the local copy:
$ git branch -d my-old-branch

To delete the remote copy:
$ git push origin –delete my-old-branch

How to clone a specific branch

$ git clone -b my-branch git@github.com:user/myproject.git

How to checkout remote branch from within an existing clone

$ git fetch origin

See the available branches:
$ git branch -r

$ git checkout -b my-branch

How to switch to a local branch from within an existing clone

$ git checkout my-branch

How to restore an accidentally deleted file

$ git checkout path/to/my/deleted/file.html

How to create a new Branch from an existing Tag

$ git pull origin master
$ git fetch –all
$ git tag -l
$ git checkout -b myNewBranch myExistingTag
$ git push origin myNewBranch

How to merge a branch

Checkout the branch you wish to merge into
$ git checkout master

Merge with the branch you’re merging form.
$ git merge myOtherBranch

** manually fix any conflicts **

Push back
$ git commit -a -m’Merge with branch myOtherBranch’

$ git push origin master

How to create a tag

List current tags:
$ git tag -l

Create the tag
$ git tag -a v1.4.0 -m ‘my version 1.4.0’

List current tags:
$ git tag -l

Push the tag back to the remote server:
$ git push origin v1.4.0

How to clone a specific tag

Clone the repo:
$ git clone git@github.com:user/myproject.git

List the available tags:
$ git tag -l

Checkout the desired tag:
$ git checkout tags/<tagname>

Deploy from a tag

$ cd “${DEPLOY_TREE}”
$ git fetch –all
$ git checkout –force “${TARGET}”

from: http://grimoire.ca/git/stop-using-git-pull-to-deploy

How to ignore all local changes for a certain amount of time

$ git update-index –skip-worktree

To undo:
$ git update-index –no-skip-worktree

Leave a Reply

Your email address will not be published. Required fields are marked *