This file serves as a quick reference for commonly used Git commands.
-
git config --global user.name "Your Name"
Sets the name you want attached to your commits. Use--global
to set this for all repositories. -
git config --global user.email "your.email@example.com"
Sets the email you want attached to your commits. Use--global
to set this for all repositories. -
git config --list
Lists all Git configurations currently set on your system.
git init
Initializes a new Git repository in the current directory.
-
git add <file>
Stages a specific file (or files) for commit. -
git commit -m "message"
Commits staged changes with a message describing the commit.
git push
Pushes local commits to a remote repository.
-
git diff
Shows differences between the working directory and the staging area. -
git status
Displays the status of the working directory and the staging area. -
git log
Shows the commit history.
git reset --hard <commit ID>
Resets the repository to the specified commit, discarding all changes after that commit.
git checkout -b <branch name>
Creates and switches to a new branch with the specified name.
There are three main commands for merging changes between branches:
-
git cherry-pick <commit ID>
Adds specific commits from one branch to another (often used to apply single commits tomain
). -
git merge <branch name>
Merges changes from the specified branch into the current branch without reordering commits. -
git rebase <branch name>
Merges changes from the specified branch into the current branch with a linear commit history.
Use these commands to manage your Git workflow effectively!