Git Commands that are very useful …

Kaltaani
2 min readJun 27, 2023

--

Git is a popular version control system used by developers to manage and track changes in their code repositories. Here are some commonly used Git commands along with brief explanations:

1. `git init`: Initializes a new Git repository in the current directory.

2. `git clone [repository]`: Creates a local copy of a remote repository on your machine.

3. `git add [file(s)]`: Adds file(s) to the staging area, preparing them for a commit.

4. `git commit -m “Commit message”`: Records changes to the repository with a descriptive commit message.

5. `git status`: Displays the current status of the repository, including modified files and files ready to be committed.

6. `git log`: Shows a list of past commits, including commit messages, authors, timestamps, and unique identifiers (SHA).

7. `git pull`: Fetches changes from a remote repository and merges them into the current branch.

8. `git push`: Uploads local commits to a remote repository, updating it with your latest changes.

9. `git branch`: Lists all branches in the repository. The current branch is indicated with an asterisk.

10. `git checkout [branch]`: Switches to the specified branch or commit.

11. `git merge [branch]`: Combines the changes from the specified branch into the current branch.

12. `git remote add [name] [url]`: Adds a remote repository with the specified name and URL.

13. `git remote -v`: Lists all remote repositories associated with the current repository.

14. `git diff`: Shows the differences between the working directory and the staging area.

15. `git reset [file]`: Unstages a file, removing it from the staging area.

16. `git reset [commit]`: Moves the branch pointer to a specific commit, discarding subsequent commits.

17. `git revert [commit]`: Reverts the changes made in a specific commit, creating a new commit that undoes those changes.

18. `git stash`: Temporarily saves changes that are not ready to be committed, allowing you to switch branches without losing work.

19. `git tag [name]`: Creates a tag at the current commit, often used to mark important milestones or releases.

20. `git rm [file]`: Removes a file from the repository and stages the deletion.

These are just a few of the many Git commands available. Git is a powerful tool with a wide range of features, so it’s recommended to explore the official Git documentation and resources for more in-depth understanding and usage of Git commands.

--

--