Git and GitHub(command mainly for windows)

How to check git version in windows cmd or gitBash?
git --version
To get full option in git :
git config --e
To get global username and email:
git config --global user.name
git config --global user.email
To set global username and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
To open vs code using cmd:
code .
To create directory and using that directory then open it in vs code using cmd:
mkdir directory_name
cd directory_name
code .
What is .gitignore?
The .gitignore
file lets you exclude files from being tracked by Git.
For example:
You don’t want to track temporary files, build folders, or secrets.
Git skips whatever matches the patterns inside
.gitignore
.
Git command:
git init - Initialized empty Git repository like C:/Users/name/gitHubBasic/.git/
This sets up a.git
folder to track your project.git status - Shows what's been modified, added, or deleted — and whether anything is staged or not.
The below three command use for:Files in the staging area are ready to be committed.
git add <file_name> - add a single file
git add . - add all files in the current folder (and subfolders)
git add *.html - add all HTML files
git commit -m "Your message here" - This saves a snapshot of your staged changes.
🔸 The
-m
lets you write a message describing what changed.git branch - Shows a list of all branches in your repo. The current one is marked with *.
git branch new-feature - This creates a new branch named new-feature but doesn’t switch to it yet.
git checkout new-feature - This moves you to the new-feature branch so you can work there.
git checkout -b new-feature - The above two steps can be done in a single command.
git branch -d branch_name - This deletes branch named branch_name.
git commit -help - This command to view the history of commits for the repository.
git merge new-email - This command to merge the current branch with the branch "new-email".
How to push projects from vs code to GitHub?
Before creating repository in gitHub, we need SSH keys.
To create SSH keys:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter file in which to save the key (/home/user/.ssh/id_rsa):
# Press Enter to accept the default path.
# Set a passphrase (optional but recommended).
Locate your public key:
Once generated, you'll have:
id_rsa
— private key (DON’T share this)id_
rsa.pub
— public key (this one you share with GitHub/GitLab)clip < ~/.ssh/id_rsa.pub # for windows # This copies your key to the clipboard.
After that go and paste this SSH key to gitHub.
Now, you can create repository.
To create respository:
set repository name(you can do also many things) and create repository.
After that you will see some steps follow them .
Command:
git remote add origin https://abc.xyz/d/e.git - This command to add the remote repository "https://abc.xyz/d/e.git" as "origin".
git push origin - This command to push the current repository to the remote origin.
git fetch origin - This command to get all the change history of the remote repository "origin".
git diff new-email - This command to show the differences between the current branch and the branch "new-email".
**git clone <repo_url> -**What it does:
Downloads all the files from the repo
Brings in the entire commit history
Sets up a remote connection called
origin
git pull [remote] [branch] - This does two things:
git fetch
→ downloads the latest changes from the remote.git merge
→ merges those changes into your current branch.When to Use It:
You've been working in a team and want the latest code from GitHub.
You want to update your local repo with the latest changes from the remote.
After doing first two command from above command, your repository is created .
Subscribe to my newsletter
Read articles from Unknown Truth directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
