GIT/GITHUB COMMANDS

Git is a powerful version control system that helps you track changes and collaborate on code. This post breaks down 11 must-know Git and GitHub commands in a beginner-friendly way. 1. git init Initializes a new Git repository in your current directory. git init This creates a hidden .git folder and allows Git to start tracking your project. 2. git add Stages changes for the next commit. git add file.txt This tells Git which files you want to include in your next commit. 3. git commit Saves staged changes to your local repository with a message. git commit -m "commit message" Each commit creates a snapshot of your project that you can refer back to. 4. git push Sends your commits to a remote GitHub repository. git push origin main Make sure your remote is already set and you're pushing to the correct branch. 5. git status Displays the current state of the working directory and staging area. git status It helps you understand what’s staged, unstaged, and untracked. 6. git log Shows a list of all commits in the current branch. git log You’ll see commit hashes, messages, authors, and timestamps. 7. git branch Lists all branches or creates a new one. git branch Branches help you work on features or fixes without affecting the main codebase. 8. git branch -M Renames a branch (commonly used to rename master to main). git branch -M main 9. git config --global user.name Sets your Git username globally. git config --global user.name "Your Name" This name will appear in your commit history. 10. git config --global user.email Sets your Git email globally. git config --global user.email "your.email@example.com" Used alongside your username to identify you in commits. 11. git remote add origin Connects your local repository to a GitHub repository. git remote add origin https://github.com/username/repo.git This allows you to push your local code to a remote location.

Apr 23, 2025 - 19:33
 0
GIT/GITHUB COMMANDS

Git is a powerful version control system that helps you track changes and collaborate on code.

This post breaks down 11 must-know Git and GitHub commands in a beginner-friendly way.

1. git init

Initializes a new Git repository in your current directory.
git init
This creates a hidden .git folder and allows Git to start tracking your project.

2. git add

Stages changes for the next commit.
git add file.txt
This tells Git which files you want to include in your next commit.

3. git commit

Saves staged changes to your local repository with a message.
git commit -m "commit message"
Each commit creates a snapshot of your project that you can refer back to.

4. git push

Sends your commits to a remote GitHub repository.
git push origin main
Make sure your remote is already set and you're pushing to the correct branch.

5. git status

Displays the current state of the working directory and staging area.
git status
It helps you understand what’s staged, unstaged, and untracked.

6. git log

Shows a list of all commits in the current branch.
git log
You’ll see commit hashes, messages, authors, and timestamps.

7. git branch

Lists all branches or creates a new one.
git branch
Branches help you work on features or fixes without affecting the main codebase.

8. git branch -M

Renames a branch (commonly used to rename master to main).
git branch -M main

9. git config --global user.name

Sets your Git username globally.
git config --global user.name "Your Name"
This name will appear in your commit history.

10. git config --global user.email

Sets your Git email globally.
git config --global user.email "your.email@example.com"
Used alongside your username to identify you in commits.

11. git remote add origin

Connects your local repository to a GitHub repository.
git remote add origin https://github.com/username/repo.git
This allows you to push your local code to a remote location.

Image description

Image description

Image description

Image description