Organized cheat sheet with copy buttons — commands & one-line descriptions.
git --version # check installed git version
git config --global user.name "Akash" # set your username globally
git config --global user.email "akash@example.com" # set your email globally
git config --global user.name # check the saved username
git config --global core.editor "code --wait" # set VS Code as default editor
# On Windows (view global config):
# c:\> type %userprofile%\.gitconfig
git init # initialize a new git repository in current folder
git status # show the status of working directory & staging area
git init once per project folder. Use git status frequently.git add filename.txt # add a file to staging area
git commit -m "add new file" # commit staged files with a message
git log # view full commit history
git log --oneline # view compact commit history
git add -p to stage hunks interactively.git branch # list all branches
git branch nav-bar # create new branch called 'nav-bar'
git checkout nav-bar # switch to 'nav-bar' branch
git switch nav-bar # switch to 'nav-bar' branch
git switch -c nav-bar # create + switch to 'nav-bar'
git checkout -b nav-bar # create + switch to 'nav-bar'
git merge nav-bar -m "merge branch" # merge 'nav-bar' into current branch
git switch & git restore over older checkout for clarity.git diff --staged # show differences of staged files
git checkout <commit_id> # move (checkout) to a specific commit
git checkout master # move back to master/main branch
git remote -v # check remote repositories
git remote add name url # add new remote
git remote add origin <url> # add remote 'origin'
git remote rename oldname newname # rename remote
git remote remove name # remove a remote
origin. Use descriptive remote names for multiple repos.git push <remote> <branch> # push branch to remote
git push origin main # push main branch to origin
git push <remote> local:remote # push local branch to remote with diff name
git push -u origin main # push and set upstream (track remote branch)
git pull origin main # fetch + merge latest changes from remote
# If you see 'refusing to merge unrelated histories', use:
# git pull origin main --allow-unrelated-histories
--force pushes. Prefer git pull --rebase to keep linear history when collaborating.Install Git Graph extension in VS Code # visualize branches & commits
Press CTRL + , in VS Code and uncheck Git from the Exclude section
Press q to quit any ongoing git pager (eg. git log output)