Skip to content

Instantly share code, notes, and snippets.

@sibinx7
Last active August 24, 2019 11:33
Show Gist options
  • Save sibinx7/a11777908baff70743775aa495c354d0 to your computer and use it in GitHub Desktop.
Save sibinx7/a11777908baff70743775aa495c354d0 to your computer and use it in GitHub Desktop.
Git tutorials

Git advanced

Multiple SSH Keys

eval "$(ssh-agent -s)"
ssh-add ~/.ssh <SSH PUBLIC/PRIVATE KEY PATH>

Ignore file only locally

  • Goto .git/info/exclude file
  • Add your files and save it
  • git status ti check changes, ig not changed, then run git update-index --no-assume-unchanged [<file>|<pattern>]

Git submodules

  • Download latest: git submodule update --init --recursive
  • Update latest: git submodule update --remote --merge
  • Remove submodules
# Delete it from .gitmodules 
# Update .gitmodules 
# Delete from `.git/config`

git rm --cached <sub-module-path>
rm -rf .git/modules/<sub-module-path>
rm -rf <sub-module-path>

Git add all file except file or folder

git add -u
git reset -- main/dontcheckmein.txt [-- main/*]

Branches removed in remote, Update same on local

  • git fetch --all --prune

Display branch details on terminal

# Add Git branch and color scheme
function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[01;33m\]$(__git_ps1)\[\033[01;34m\] \$\[\033[00m\] '
# export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[01;33m\]$(__git_ps1)\[\033[01;34m\] \$\[\033[00m\] '
# EOF GIT BRANCH

Emojies in github

Check cached and Ignore files

git ls-files // List all cached files 
git ls-files | grep "env" // Check 'env' on cached files 
git ls-files --other --exclude=*.env --ignored // Check whther 'env' file is ignored 

Ignore files locally

Different methods to ignore files -

Method 1:

Edit file .git/info/exclude

Method 2

  git rm --cached <files>

Method 3

  git update-index --assume-unchanged path/to/file.txt
  
  git update-index --no-assume-unchanged path/to/file.txt (revert)

Bad Index issue

rm -f .git/index
git reset

Git clean

git clean -df // removed untracked directory (d) and untracked files (f)

Git Hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment