MAL's Logo

GIT Basics

💡 Basic Git commands used in a professional environment.

Breakdown

The Most Used

  • git init - initialise a Git repository, ergo, let Git know that it should start tracking changes in that folder
  • git add . - track all changed files, preparing to be committed
  • git commit -m "message here" - commit files with a message
  • git push -u origin "branchName" - push to remote for the first time
  • git stash - temporarily saves changes, often used when the changes are not ready to be committed yet but you need to check out another branch
  • git checkout -b "newBranchName" - to create a new local branch and switching to it
  • git switch "existingBranchName" - to switch between existing branches
  • git pull - fetch changes from remote repository
  • git merge "branchName" - merge the named branch with the current one
  • Undo last commit locally and remotely
  • // undo last commit in your local branch
    git reset --hard HEAD~1
    // push remote branch forward to match the local one
    git push -f

    Extra

  • git status - state of the current working tree
  • git log - spits out a list of all the commits
  • git stash list - list all the stashes
  • git stash drop - delete the latest stash
  • git config:
  • // set the username
    git config --global user.name "username"
    // set the email address
    git config --global user.email "email@example.com"

    Resources

  • https://git-scm.com/doc
  • MAL's Logo© 2021 – 2026 MAL. All rights reserved.