Git Cheatsheet

Task Command Description
Configure git git config --global user.name "Your Name" Set name for commits
git config --global user.email "you@example.com Set email address for commits
git config --global user.email Check email is set correctly
git config --list List all configuration values
Need help? git config --help List all config options
Change directory and create folder cd C:/Users/partrh/GitHub Set working directory
mkdir cheatsheets Create working directory
cd cheatsheets Change working directory
ls List contents of working directory
Initialise existing repo git init Track directory with git
rm -rf .git Remove git from directory
touch .gitignore Create .gitignore file
Staging git add cheatsheet.md Add particular file to staging area
git reset cheatsheet.md Remove particular file from staging area
git reset Remove all files from staging area
Commit git commit -m "Meaningful commit message" Take a snapshot of file(s) with message
git commit --amend Change commit message
Fork git clone https://github.com/NBS-Nigeria/ISIC-ISCO-CODER.git Clone remote repo in current directory
Pull and push git fetch Retrieve history from remote branches
git pull Pull latest changes from remote into local repo
git push Push local commits to remote repo
Create branches git branch Check current branch
git branch -a Check local and remote branches
git branch dev Create new branch called β€˜dev’
git checkout dev Switch to new branch
git push -u origin dev Push new branch to GitHub
Merge branches git checkout main Switch to main branch
git pull origin main Pull changes from remote main branch
git branch --merged Show branches that have been merged
git merge dev Merge dev branch
git push origin main Push to main branch
Deleting branches git branch --merged Show merged branches
git branch -d dev Delete dev branch locally
git branch -a Check branches on remote
git push origin --delete dev Delete branch remotely

Typical workflow

$ git branch dev # create branch
$ git checkout dev # switch to dev branch
$ git status # check current branch
$ git add . # add changed files to staging area
$ git commit -m "I updated this..." # commit changed files
$ git push -origin dev # push dev branch to remote
$ git checkout main # switch to main branch
$ git pull origin main # pull latest changes to main
$ git merge dev # merge dev to main branch
$ git push origin main # push main branch
$ git branch -d dev # delete local dev branch
$ git push origin --delete dev # delete remote dev branch