Jump to navigation Jump to search

Starting out

Notify git of your identity and ID:

git config --global "yourname@yoursite.yourdomain"
git config --global yourID

To avoid entering git userID and password:

git config --global credential.helper 'cache --timeout 7200'

To address the usual "^M" problem when switching between Linux and Windows environments

$ git config --global core.autocrlf true
# Remove everything from the index
$ git rm --cached -r .

# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add

# Commit
$ git commit -m "Fix CRLF"

(Also see

Restoring Files

First, see this link:

A recipe that may work well:

git log --diff-filter=D --summary # finds deleted files
git checkout $commit~1 filename # where "$commit" stands for the actual commit name (a long string)

In the above, it's best to operate from the top level directory of the project and use path relative to that. Also, you may want to "git add" the restored files and commit them to make it permanent.

If you want to get a specific previous revision of a file, just capture the stdout of the following command:

git show $REV:$FILE

...and rename the output as you see fit.

Undoing a commit


If you want to reverse your latest commit to the HEAD:

git reset --hard HEAD

To remove two last commits:

git reset --hard HEAD~2

gitHub quirks

Sometimes a cloned repo will end up in a state where you can't push local content. Things you might want to try:

git remote set-url origin

And in case it was not annoying enough, if you see something like "can't open display" this may help: