Links

Git

What is Git and how to use it.

What is Git?

  • Git is a popular open-source version control tool commonly used for code but can be used with any type of file
  • More information about Git can be found on its website

How do I Git it?

  • Git is typically installed by default on Linux distributions and MacOS however it will need to be installed on Windows
    • Windows: winget install git.git
    • Linux: sudo apt install git
    • MacOS: brew install git

Common Commands

  • Get additional syntax help git --help or man git
  • Download from a code repository such as GitHub git clone <repositoryName>
  • Create a new branch and switch to it git checkout -b <newBranchName>
  • View all branches git branch
  • Switch branches git branch <branchName>
  • View any changes made since the initial download git status
  • Queue files to be added to the branch git add <fileName> or git add *
  • Commit files git commit -m 'change comment'
  • Push files to its repository git push -u origin <branchName>

Modify Terminal to show current git branch

  • Update your shell's configuration file e.g., ~/.zshrc or ~/.bashrc
  • Save and then reload your shell for the changes to take effect source ~/.zshrc
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
# color #s found here: https://misc.flogisoft.com/bash/tip_colors_and_formatting
COLOR_DEF='%f'
COLOR_USR='%F{243}'
COLOR_DIR='%F{197}'
COLOR_GIT='%F{39}'
NEWLINE=$'\n'
setopt PROMPT_SUBST
export PROMPT='${COLOR_USR}%[email protected]%M ${COLOR_DIR}%d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}${NEWLINE}%% '