Basic Git Commands with Examples

Git is a popular version control system used by developers around the world. It allows you to track changes to your code, collaborate with others, and revert to previous versions if needed. Git can be used on the command line or through a graphical user interface (GUI). In this post, we’ll cover some of the most common Git commands and their example usage to help you get started with using Git.

git init: Initializes a new Git repository in your current directory.

git init my-repo

git clone: Creates a copy of a remote repository on your local machine.

git clone

git add: Adds changes to the staging area.

git add index.html

git commit: Records changes to the repository.

git commit -m "Added a new feature"

git push: Uploads changes to the remote repository.

git push origin master

git pull: Downloads changes from the remote repository.

git pull origin master

git branch: Shows all branches in the repository.

git branch

git checkout: Switches to a different branch.

git checkout development

git merge: Combines changes from one branch to another.

git merge feature-branch

git status: Shows the current state of the repository.

git status

Git is an essential tool for developers, and mastering these basic Git commands will help you get started with using Git. Remember to always commit your changes frequently and use clear commit messages to make it easier to track changes to your code. Happy coding!

Leave a Reply

Scroll to top