An open API service indexing awesome lists of open source software.

https://github.com/gvelasq/git-reference

Git command reference
https://github.com/gvelasq/git-reference

git reference

Last synced: 29 days ago
JSON representation

Git command reference

Awesome Lists containing this project

README

          

# git-reference

> Git command reference

- [terminal](#terminal)
- [setup](#setup)
- [state](#state)
- [branch](#branch)
- [remote](#remote)
- [commit](#commit)
- [stash](#stash)
- [sync](#sync)
- [rewrite history](#rewrite-history)
- [vanquish ghosts](#vanquish-ghosts)

## terminal
```bash
# navigate to a particular folder
cd ""
# navigate up a folder
cd ..
# navigate to your home folder
cd
# list items in current folder
ls
```

## setup
```bash
# check global and local git settings
git config --global -l
git config --local -l
# configure global git settings
git config --global user.name ""
git config --global user.email ""
git config --global core.editor "nano -w"
# configure local git settings
cd ""
git config --local user.name ""
git config --local user.email ""
# initialize a local git repository
cd ""
git init
# clone a remote repository
git clone
```

## state
```bash
# check git status
git status
# check git log
git log # verbose
git log --oneline # condense each commit to a single line
git log --oneline -n 5 # print only the last 5 commits
```

## branch
```bash
# list all local branches
git branch
# create a local branch
git branch
# switch between branches and update working directory
git checkout
# delete local branch only if its commits are merged upstream
git branch -d
# delete local branch unconditionally
git branch -D
# delete remote branch
git push origin :
# checkout a pull request
git fetch origin pull//head:
# list branches and their creators
git for-each-ref --sort=authorname --format "%(authorname) %(refname)"
```

## remote
```bash
# view remote settings
git remote -v
# configure 'origin' remote branch
git remote add origin
# change 'origin' remote branch URL
git remote set-url origin
# configure 'upstream' remote branch (when working with a fork)
git remote add upstream
# change 'upstream' remote branch URL
git remote set-url upstream
```

## commit
```bash
# stage one file
git add
# stage all files (danger, this stages all changes)
git add .
# unstage one file
git reset HEAD
# 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
```

## stash
```bash
# 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
```

## sync
```bash
# sync a local fork with changes made in upstream/main
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
# sync a local branch with changes made in origin/main
git fetch origin
git checkout
git merge origin/main
```

## rewrite history
```bash
# reset local and remote branches to a previous commit
git checkout
git reset --hard
git push -f origin
```

## vanquish ghosts
```bash
# prune remote branches
git fetch --prune origin
# prune upstream branches
git fetch --prune upstream
```