DEV Community


Git Fundamentals

therockstorm profile image Rocky Warren Originally published at Updated on ・1 min read

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 feature
git checkout -b new-feature
gcb 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 --all

# Check the status of your branch/commits
git status

# Switch branches
git checkout branch-name
gco branch-name
# Separate `git` plugin alias to switch back to master

# See what has changed (maybe done prior to committing, include
# the `--cached` flag to see what has changed in `staging`)
git diff

# Pull new changes down from remote (Github/Gitlab/etc.)
git pull

# Push changes to remote
git push --set-upstream origin

# Merge changes from another branch into the current one
git merge other-branch-name
gm other-branch-name

# Or, if you prefer rebase,
git rebase -i other-branch-name
grbi other-branch-name
Enter fullscreen mode Exit fullscreen mode

And that's it! 95% of the time, you'll use these commands. Google was invented for the remaining 5% 😉

Discussion (0)

Editor guide