Git Fundamentals
Git can seem overwhelming, but while performing typical day-to-day tasks, you'll use only about ten commands. If you happen to use Oh My ZSH, the included git
plugin adds many aliases. Below each command, I've included the corresponding alias.
# Start a new branch for a new featuregit checkout -b new-featuregcb new-feature# Commit as you make changes (the --all adds changed files to# `staging`)git commit --all --message "your commit message"gcam "your commit message"# Add new or deleted files to `staging` (the `git commit# --all` above only adds tracked files)git add --allgaa# Check the status of your branch/commitsgit statusgst# Switch branchesgit checkout branch-namegco branch-name# Separate `git` plugin alias to switch back to mastergcm# See what has changed (maybe done prior to committing, include# the `--cached` flag to see what has changed in `staging`)git diffgd# Pull new changes down from remote (Github/GitLab/etc.)git pullgl# Push changes to remotegit push --set-upstream origingpsup# Merge changes from another branch into the current onegit merge other-branch-namegm other-branch-name# Or, if you prefer rebase,git rebase -i other-branch-namegrbi other-branch-name
And that's it! 95% of the time, you'll use these commands. Google was invented for the remaining 5% 😉