Skip to navigation Skip to main content

Basic Git Commands

Git Command You Will Ever Need as a Programmer

Git is a free, open-source version control system that helps you track code changes, collaborate with others, and manage projects of any size. Whether you’re new to Git or want a quick refresher, this guide covers the essential Git commands every developer should know.


Why Use Git?

  • Track changes: Keep a history of your code and easily revert mistakes.
  • Collaborate: Work with others without overwriting each other’s work.
  • Backup: Store your code safely, both locally and in the cloud.

Getting Started with Git


The Git Workflow: 4 Simple Steps

  1. Working Directory: Edit your files here.
  2. Staging Area: Prepare files for commit.
  3. Repository: Store committed snapshots.
  4. Remote: Sync with others (push/pull).

Essential Git Commands (with Examples)

1. Set Up Your Identity

Configure your name and email for commits:

git config --global user.name "Your Name"
git config --global user.email youremail@example.com

2. Initialize a Repository

Start tracking a project:

git init

3. Clone a Repository

Copy a remote project to your computer:

git clone https://github.com/rafayethossain/rafayethossain.github.io.git

4. Check Status

See which files have changed:

git status

5. Stage Changes

Prepare files for commit:

git add .
  • Stage all files: git add .
  • Stage a specific file: git add filename.txt
  • Stage by extension: git add *.py

6. Commit Changes

Save a snapshot of your work:

git commit -m "Describe your changes"

7. Push to Remote

Upload your commits to a remote repository:

git push

8. Pull from Remote

Download and merge changes from the remote:

git pull

More Useful Git Commands

  • git reset – Unstage files or undo commits.
  • git rm filename – Remove a file from the repo.
  • git branch – List, create, or delete branches.
  • git checkout branchname – Switch branches.
  • git merge branchname – Merge another branch into your current one.
  • git fetch – Download new data from remote without merging.
  • git log – View commit history.
  • git diff – See changes between commits or working directory.

Common Terminal Commands (Windows)

  • touch filename – Create a new file.
  • mkdir foldername – Create a new folder.
  • cd foldername – Change directory.
  • pwd – Show current directory.
  • ls – List files in directory.

Pro Tips for Mastering Git

  • Practice these commands regularly to build confidence.
  • Use clear commit messages to describe your changes.
  • Don’t be afraid to experiment—mistakes are part of learning.

Ready to Level Up Your Git Skills?

Git is a must-have tool for every developer. Start using these commands in your daily workflow and watch your confidence grow. If you found this guide helpful, share it with your friends or team. Have questions or want to share your own Git tips? Leave a comment or connect with me on LinkedIn.

Happy coding—and may your commits always be clean!


Share: X (Twitter) Facebook LinkedIn