Git Product home page Git Product logo

git-tips's Introduction

Git "tips"

This repository contains some tips for git.

Oh My Zsh

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.

Installation zsh:

Ubuntu:

$ sudo apt-get install zsh

Arch Linux:

$ sudo pacman -S zsh

Installation Oh My Zsh:

$ sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
$ chsh -s $(which zsh)

Enable auto updates - set DISABLE_UPDATE_PROMPT to true:

$ less ~/.zshrc
...
DISABLE_UPDATE_PROMPT="true"
...

Plugins (see GitHub wiki for more plugins) can be activated in plugins sections:

$ less ~/.zshrc
...
plugins=(git ripgrep)
...

See other plugins: git, ripgrep, python, pip, rust, kubectl, docker, docker-compose

Git commands/aliases with Oh My Zsh git plugin:

Short Command
g git
gst git status
ga git add
gco git checkout
gd git diff
gdw git diff --word-diff
gdca git diff --cached
gdcw git diff --cached --word-diff

Git global hooks - git 2.9+

Pre-push script: pre-push - will warn if pushing to protected branch, script is available in GitHub repository.

English messages

To enable english messages add alias in Shell RC file (bash - .bashrc, zsh - .zshrc) at the end of the file (to avoid anomalies):

alias git='LANGUAGE=en_US.UTF-8 git'

Custom aliases

alias git_compare_word='git diff --no-index --word-diff'
alias diff_git_word='git_compare_word'
alias git_compare='git diff --no-index'
alias diff_git='git_compare'

Git external tools

  • GitUI provides you with the comfort of a git GUI but right in your terminal

Commands

git commit

Pushing empty commit (example 3), e.g. with releasing Docker image:

git commit -m "[pre-release] Test docker image" --allow-empty

Amending commit with current date (example 2):

git commit --amend --date=now

git rebase

Rebase with master branch:

git rebase master

Rebase current branch in interactive mode (example 1):

git rebase -i HEAD~3

git checkout

Getting some-file.txt from master branch:

gco master -- some-file.txt

git diff

Check last 2-commit changes:

git diff HEAD~2

or shorter:

gd HEAD~2

Comparing master and develop branches:

git diff master..develop

Comparing 2 non-git files: 1.txt and 2.txt:

git diff --no-index --word-index 1.txt 2.txt

shorter:

gdw --no-index 1.txt 2.txt

Comparing 2 non-git directories dir1 and dir2:

git diff --no-index dir1 dir2

shorter:

gd --no-index dir1 dir2

Comparing changes with context (only changes will be available - context may be changed by U argument):

git diff -U0

Comparing only deleted changes:

git diff --diff-filter=d

git log

One line commits:

git log --oneline

git stash

Stash uncommitted changes:

git stash

Pop stashed changes:

git stash pop

List stashed changes:

git stash list

Drop stashed changes (stashed changes are indexed from 0)

git stash drop stash@{0}

or remove all:

git stash clear

git grep

Search with grep in git:

git grep 'my_secret_password'

Examples

Example 1

Example 2

  • Example 2 - override commit message and fix typo
  • read README for details
  • branch commit_amend

Example 3

  • Example 3 - add empty (without changes) commit (with message only)
  • read README for details
  • branch commit_empty

git-tips's People

Contributors

kaczla avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.