r/backtickbot • • Dec 13 '20

https://np.reddit.com/r/learnjava/comments/kbxl6s/why_is_learning_git_commands_necessary/gfmsm7o/

You only need a few commands. If you are trying new stuff on 2-4 files, make a bunch of changes, git is needed to revert changes to last working state.

Make a script and put it in your path, so you can just be in a folder and type like gitinit to run it:

#!/bin/bash

git init
git config --global user.email "[email protected]"
git config --global user.name "xxxx"
git add .
git commit -m "Initial commit"
git checkout -b develop

My most commonly used or fav git commands

# default oh-mh-zsh aliases I use a lot
alias gs='git status'
alias gco='git checkout'
alias grhh='git reset --hard'
alias grc='git reset --hard && git clean -f'
alias gms='git merge --squash'  # my own
alias gst='git stash'

alias glgg='git log --graph'
alias glods='git log --graph --pretty='\''%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'\'' --date=short'

A really powerful thing I do is keep the git log clean/minimal. So make a bunch of commits on a work/dev branch like this, then merge into a SINGLE commit. It looks like this:

git checkout -b develop
# do some work, make 3 commits

git checkout master
git merge --squash develop 
git commit -m "3 commit history becomes this single one"

I screw up and don't have a perfect .gitignore file. This is how you dont clutter your git log using the previous trick with squash. This is how you use the command git rm -r --cached .

# first update your gitignore file, then add all and commit
git rm -r --cached .    # deletes .gitignore files from remote repo, but not from master disk
git add .
git commit -m "Quit tracking files in my gitignore file."

The previous block you would do a git checkout to a tmp/dev branch, do a bunch of commits and the git rm thing. Commit. Then go back to like master with git checkout master and do the --squash thing so that updating your .gitignore and deleting the remote file doesn't take 3 commits, but only 1.

1 Upvotes

1 comment sorted by