Git commands cheatsheet
Getting Started:
git init
- Initializes a new Git repository in the current directory.git clone <url>
- Creates a local copy of a remote repository specified by the URL.git config -l
- To check configuration fo the gitgit config --global user.name <your name>
- To configure your username on gitgit config --global user.email <your email>
- To configure your email on git
Basic Workflow:
git add <file>
- Stages changes in a specific file for the next commit.git add .
- Stages changes in all tracked files for the next commit.git commit -m "<commit message>"
- Commits changes with a specified message.git status
- Shows the current state of the repository, including any untracked or modified files.git diff
- Shows the differences between the current changes and the previous commit.git log
- Shows the commit history of the repository.
Branches:
git branch
- Shows a list of all branches in the repository.git branch <branch-name>
- Creates a new branch with the specified name.git checkout <branch-name>
- Switches to the specified branch.git merge <branch-name>
- Merges the specified branch into the current branch.git branch -d <branch-name>
- Deletes the specified branch.
Remote Repositories:
git remote add <remote-name> <remote-url>
- Adds a new remote repository.git remote -v
- Shows a list of all remote repositories and their URLs.git push <remote-name> <branch-name>
- Pushes local changes to a remote repository.git pull <remote-name> <branch-name>
- Pulls remote changes to the local repository.
Miscellaneous:
git rm <file>
- Removes a file from the repository.git reset
- Resets the repository to the previous commit.git tag <tag-name>
- Creates a new tag with the specified name.git fetch
- Retrieves the latest changes from the remote repository without merging them.