Skip to content

Instantly share code, notes, and snippets.

@sameeramin
Last active July 31, 2023 06:11
Show Gist options
  • Save sameeramin/acf5e3d8a94abb21c48b40ad805ff33d to your computer and use it in GitHub Desktop.
Save sameeramin/acf5e3d8a94abb21c48b40ad805ff33d to your computer and use it in GitHub Desktop.
Git Cheat Sheet

Sure, here's a basic Git cheat sheet in Markdown format for beginners:

Git Cheat Sheet for Beginners

Configuration

Configure Git with your name and email:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

If you're using Mac then you might want to store your git credentials using osxkeychain.

git config --global credential.helper osxkeychain

Creating Repositories

Initialize a new Git repository:

git init

Clone an existing repository:

git clone <repository-url>

Basic Commands

Check the status of your working directory:

git status

Add changes to the staging area:

git add <file-name>

Commit changes to the repository:

git commit -m "Your commit message here"

Remove changes from staging area

git restore --staged <file-name>

Branching

List all branches:

git branch

Create a new branch:

git branch <branch-name>

Switch to a branch:

git checkout <branch-name>

Create and switch to a new branch:

git checkout -b <branch-name>

Merge changes from one branch into the current branch:

git merge <branch-name>

Delete a branch:

git branch -d <branch-name>

Remote Repositories

Add a remote repository:

git remote add <remote-name> <repository-url>

List all remotes:

git remote -v

Push changes to a remote repository:

git push <remote-name> <branch-name>

Pull changes from a remote repository:

git pull <remote-name> <branch-name>

History

View commit history:

git log

View changes for a specific file:

git log -p <file-name>

Undoing Changes

Discard changes in the working directory:

git checkout -- <file-name>

Unstage changes from the staging area:

git reset HEAD <file-name>

Amend the last commit:

git commit --amend

Miscellaneous

Show the differences between commits, branches, or files:

git diff

Ignore files with a .gitignore file:

Create a file named .gitignore and list the files/directories you want to ignore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment