Sure, here's a basic Git cheat sheet in Markdown format for beginners:
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
Initialize a new Git repository:
git init
Clone an existing repository:
git clone <repository-url>
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>
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>
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>
View commit history:
git log
View changes for a specific file:
git log -p <file-name>
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
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.