Skip to content

Instantly share code, notes, and snippets.

@jacob-faber
Last active November 23, 2015 20:43
Show Gist options
  • Save jacob-faber/4e3b0a7ea15dded1c3ac to your computer and use it in GitHub Desktop.
Save jacob-faber/4e3b0a7ea15dded1c3ac to your computer and use it in GitHub Desktop.
Git cheatsheet

Git cheatsheet

Setup

git config --global user.name <name>
git config --global user.email <email>
git config --system core.editor <editor>
git config --global --edit - open global settings

<repo>/.git/config – Repository-specific settings.

~/.gitconfig – User-specific settings. This is where options set with the --global flag are stored.

$(prefix)/etc/gitconfig – System-wide settings.

Structure

Init

git clone <repo> <directory>

git init

git remote add origin https://github.com/user/repo.git


## Stage 0 (Working directory)

#### Undo changes
>```
git revert <commit>

Generate a new commit that undoes all of the changes introduced in <commit>, then apply it to the current branch. Reverting should be used when you want to remove an entire commit from your project history.

git reset ... TODO

Navigating in git

git checkout <master || commit>

> Copy `<file>` from branch/commit to staging area


## Stage 1 (Staging area)

#### Adding files to staging area

git add <file || directory>



>```
git add -p

Interactive patch mode

  • y to stage the chunk
  • n to ignore the chunk
  • s to split it into smaller chunks,
  • e to manually edit the chunk
  • q to exit

Removing files from staging area

git reset HEAD <file || directory>

Stage 2 (Git repository)

Save Files files from Staging area (git will never change them unless explicitly asked to)

git commit

Launches editor to add commit message



#### Resources
[Atlassian git tutorial][0]
[0]: https://www.atlassian.com/git/tutorials/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment