Useful Git Commands


   01 Sep 2021

git-init

git-init - Create an empty Git repository or reinitialize an existing one

git init [OPTIONS]

Examples

git init

git-config

git-config - Get and set repository or global options

git config [OPTIONS]

Examples


Email Address & Username

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

Default Branch Name

git config --global init.defaultBranch main

Aliases

git config --global alias.add-commit '!git add -A && git commit'

If using a repo setup in windows and then running git on linux

git config --global core.autocrlf input

git-status

git-status - Show the working tree status

git status [OPTIONS] [PATHSPEC]

Examples

git status

git-add

git-add - Add file contents to the index

git add [OPTIONS] [PATHSPEC]

Examples

git add .
git add index.html
git add git-*.sh

git-stash

git-stash - Stash the changes in a dirty working directory away

git stash list [OPTIONS]

Examples

git stash -u [push]
git stash pop
git stash list

git-commit

git-commit - Record changes to the repository

git commit [OPTIONS] [PATHSPEC]

Examples

git commit -am "commit message"
git commit --amend -am "amended commit message"
git commit --amend

git-gui

git-gui - A portable graphical interface to Git

git gui [COMMAND] [ARGUMENTS]

Examples

git gui

git-reset

git-reset - Reset current HEAD to the specified state

git reset [OPTIONS] [PATHSPEC]

Examples

git reset --soft HEAD~1
git reset --hard HEAD~1

git-fsck

git-fsck - Verifies the connectivity and validity of the objects in the database

git fsck [OPTIONS]

Examples

git fsck

git-reflog

git-reflog - Manage reflog information

git reflog [OPTIONS]

Examples

git reflog expire --expire=now --all

git-gc

git-gc - Cleanup unnecessary files and optimize the local repository

git gc [OPTIONS]

Examples

git gc --prune=now

git-remote

git-remote - Manage set of tracked repositories

git remote [OPTIONS]

Examples

git remote add origin https://github.com/USERNAME/REPO_NAME.git

git-pull

git-pull - Fetch from and integrate with another repository or a local branch

git pull [OPTIONS] [REPO_NAME] [REFSPEC]

Examples

git pull

git-push

git-push - Update remote refs along with associated objects

git push [OPTIONS] [REPO_NAME] [REFSPEC]

Examples

git push
  Categories:   development
  Tags:   git   dangling-commits   dangling-blobs   remove-dangling-commits   remove-dangling-blobs