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
- Host: GitHub
- URL: https://github.com/gvelasq/git-reference
- Owner: gvelasq
- License: mit
- Created: 2022-02-17T02:59:46.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-28T06:35:41.000Z (about 4 years ago)
- Last Synced: 2025-03-09T17:45:53.183Z (over 1 year ago)
- Topics: git, reference
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```