DEV Community

MOHAMED ABDULLAH
MOHAMED ABDULLAH

Posted on

Basic Git Commands with Explanations

git init

Command:
git init

Explanation:
Initializes a new Git repository in your project folder. It creates a hidden .git directory that Git uses to track changes.

git status

Command:
git status
Explanation:
Shows the current state of your files — what's changed, what's staged for commit, and what files are untracked.

git add or git add .

Command:
git add index.html
or add all files
git add .

Explanation:
Adds file(s) to the staging area, which means you're telling Git “I want to include these files in the next commit.”

git commit -m "your message"

Command:
git commit -m "Add homepage layout"

Explanation:
Takes everything in the staging area and saves a snapshot of it. The -m flag lets you write a short message describing the change.

git log

Command:

git log

Explanation:
Shows the history of commits in the current branch. Great for seeing who changed what and when.

git remote add origin

Command:
git remote add origin https://github.com/yourname/project.git

Explanation:
Links your local project to a remote repository like GitHub or GitLab.

git push -u origin main

Command:
git push -u origin main

Explanation:
Uploads (pushes) your local code to the remote repo for the first time. The -u flag sets the upstream, so next time you can just use git push.

git pull

Command:
git pull

Explanation:
Downloads the latest changes from the remote repository and merges them into your local branch.

git clone

Command:
git clone https://github.com/user/project.git

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

git branch

Command:
git branch

Explanation:
Lists all branches in your repository. The current branch is marked with a *.

git checkout -b

Command:
git checkout -b feature/homepage

Explanation:
Creates a new branch and switches to it immediately.

git merge

Command:
git merge feature/homepage
Explanation:

Combines another branch into your current branch. Useful when you're done working on a feature.

Optional Cleanup
🔹 git rm
Deletes a file from both your working directory and Git tracking.

🔹 git reset
Unstages files from the staging area.

reference link :
https://git-scm.com/docs

Top comments (1)

Collapse
 
payilagam_135383b867ea296 profile image
Payilagam

Good start! Keep it up!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.