Git
What is Git and how to use it.
- Git is a popular open-source version control tool commonly used for code but can be used with any type of file
- 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
- Get additional syntax help
git --help
orman 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>
orgit add *
- Commit files
git commit -m 'change comment'
- Push files to its repository
git push -u origin <branchName>
- 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}%n@%M ${COLOR_DIR}%d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}${NEWLINE}%% '
Last modified 5mo ago