Skip to content

Commit

Permalink
Add commands and simplify index
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelasq committed Jul 30, 2018
1 parent 4e96072 commit b08df99
Showing 1 changed file with 62 additions and 25 deletions.
87 changes: 62 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

A cheatsheet of Git commands.

- [cd, ls](#terminal-navigation)
- [git init, git config](#git-setup)
- [status, log](#state-checking)
- [editor](#git-editor)
- [git remote](#remote-branch)
- [git add, git commit](#add-and-commit)
- [delete local and remote branch](#delete-local-and-remote-branch)
- [terminal](#terminal)
- [setup](#setup)
- [state](#state)
- [branch](#branch)
- [remote](#remote)
- [commit](#commit)
- [stash](#stash)
- [sync](#sync)
- [rewrite history](#rewrite-history)

## terminal navigation
## terminal
```bash
# navigate to a particular folder
cd "<path>"
Expand All @@ -22,11 +24,8 @@ cd
ls
```

## git setup
## setup
```bash
# initialize a git repository
cd "<desired-path>"
git init
# check global and local git settings
git config --global -l
git config --local -l
Expand All @@ -38,9 +37,14 @@ git config --global core.editor "nano -w"
cd "<desired-path-for-local-settings>"
git config --local user.name "<local-full-name>"
git config --local user.email "<local-email>"
# initialize a local git repository
cd "<desired-path>"
git init
# clone a remote repository
git clone <https-origin-url>
```

## state checking
## state
```bash
# check git status
git status
Expand All @@ -50,7 +54,23 @@ git log --oneline # condense each commit to a single line
git log --oneline -n 5 # print only the last 5 commits
```

## remote branch
## branch
```bash
# list all local branches
git branch
# create a local branch
git branch <local-branch-name>
# switch between branches and update working directory
git checkout <branch-name>
# delete local branch only if its commits are merged upstream
git branch -d <local-branch-name>
# delete local branch unconditionally
git branch -D <local-branch-name>
# delete remote branch
git push origin :<remote-branch-name>
```

## remote
```bash
# view remote settings
git remote -v
Expand All @@ -64,34 +84,51 @@ git remote add upstream <https-origin-url>
git remote set-url upstream <https-origin-url>
```

## add and commit
## commit
```bash
# stage one file
git add <file.ext>
# stage all files (danger, this stages all changes)
git add .
# unstage one file
git reset HEAD <file.ext>
# commit with message
git commit -m "Message"
# amend a local commit
git commit --amend # this will open up the git editor
# push local commits to origin
git push origin <remote-branch-name>
```

## delete local and remote branch
## stash
```bash
# delete local branch only if its commits are merged upstream
git branch -d <local-branch-name>
# delete local branch unconditionally
git branch -D <local-branch-name>
# delete remote branch
git push origin :<remote-branch-name>
# list all stashed files
git stash list
# stash all modified files without committing
git stash
# restore the most recent stashed files
git stash pop
# drop the most recent stashed files
git stash drop
```

## useful workflows
## sync
```bash
# sync a fork with an upstream repository
# sync a local fork with changes made in upstream/master
git fetch upstream
git checkout master
git merge upstream/master
# sync a branch with new changes made in master
git push origin master
# sync a local branch with changes made in origin/master
git fetch origin
git checkout <branch-name>
git merge origin/master
```

## rewrite history
```bash
# reset local and remote branches to a previous commit
git checkout <local-branch-name>
git reset --hard <sha-of-last-commit-to-keep>
git push -f origin <remote-branch-name>
```

0 comments on commit b08df99

Please sign in to comment.