Managing code and collaborating with others can be a daunting task, but Git makes it easy. This cheatsheet is here to help you take your Git skills to the next level by providing a comprehensive list of 30 essential commands. From initializing a new repository to merging changes, this cheatsheet covers all the basics you need to know to streamline your workflow and make your life as a developer much easier. Whether you're new to Git or an experienced user, this cheatsheet is a valuable resource to have on hand.
- Initialize a new repository:
git init
- Clone an existing repository:
git clone [repository url]
- Check the status of your repository:
git status
- Add changes to the staging area:
git add [file name]
- Commit changes:
git commit -m "[commit message]"
- View the commit history:
git log
- View the difference between the working directory and the staging area:
git diff
- View the difference between the staging area and the last commit:
git diff --staged
- Discard changes in the working directory:
git checkout [file name]
- Discard changes in the staging area:
git reset [file name]
- Discard a commit:
git revert [commit hash]
- Remove a file from the repository:
git rm [file name]
- Rename a file in the repository:
git mv [old file name] [new file name]
- Show the branches in the repository:
git branch
- Create a new branch:
git branch [branch name]
- Switch to a different branch:
git checkout [branch name]
- Merge changes from one branch to another:
git merge [branch name]
- Show remote repositories:
git remote
- Show remote repositories:
git remote -v
- Add a new remote repository:
git remote add [remote name] [repository url]
- Push changes to a remote repository:
git push [remote name] [branch name]
- Pull changes from a remote repository:
git pull [remote name] [branch name]
- Show the tags in the repository:
git tag
- Create a new tag:
git tag -a [tag name] -m "[tag message]"
- Checkout a specific tag:
git checkout [tag name]
- Show the history of a file:
git log -p [file name]
- Show the commits that contain a certain string:
git log -S [string]
- Show the commits that were made by a certain author:
git log --author=[author name]
- Show the commits that were made in a certain date range:
git log --since=[date] --until=[date]
- Show the commits that were made on a certain branch:
git log [branch name]
Please note that this is a list of commonly used Git commands, and there are many other commands that you can use as well. Additionally, each command has many options and flags that can be used to customize its behavior. I would suggest you to use the official Git documentation to learn more about the various commands and their usage.
Top comments (0)