GIT Cheatsheet

Git commands with params - little ref

Page content

Here’s a little cheatsheet: Git commands with params

git forever banner on the streetscape This streetscape image is generated by AI model Flux 1 dev.

Basic Commands

  • git init: Initialize a new Git repository
  • git clone <url>: Create a local copy of a remote repository
  • git add <file>: Stage changes for commit
  • git commit -m "<message>": Save changes to the local repository with a message
  • git status: Check the status of your working directory
  • git log: View commit history

Branching and Merging

  • git branch: List all local branches
  • git branch <branch-name>: Create a new branch
  • git checkout <branch-name>: Switch to a different branch
  • git checkout -b <branch-name>: Create and switch to a new branch
  • git merge <branch>: Merge specified branch into the current branch

Remote Repositories

  • git remote add <name> <url>: Add a remote repository
  • git push <remote> <branch>: Upload local commits to a remote repository
  • git pull: Fetch and merge changes from the remote repository
  • git fetch: Download changes from the remote repository

Undoing Changes

  • git reset <file>: Unstage changes while keeping them in the working directory
  • git reset --hard <commit>: Discard all changes and move to a specific commit
  • git revert <commit>: Create a new commit that undoes the changes from a specific commit

Advanced Commands

  • git stash: Temporarily store modified files
  • git stash pop: Apply and remove the most recent stash
  • git rebase <branch>: Reapply commits on top of another base
  • git cherry-pick <commit>: Apply a specific commit to the current branch
  • git tag <tag-name>: Create a lightweight tag at the current commit

Configuration

  • git config --global user.name "<Your Name>": Set the name for your commits
  • git config --global user.email "<you@example.com>": Set the email for your commits

Replace placeholders like <file>, <url>, <branch-name>, etc., with actual values when using these commands.

Other cheatsheets