🔭 my website | Git docs. | Exams MCQ |
---|
![]() |
---|
- linux-basics-course
- Install Git & VS Code
- Check Git Installation
- Configuring Git (Terminal)
- Create Repository
- Add and Commit (Local)
- Push to Remote Repository on GitHub
- Initialize a New Repository
- Branch Commands
- Merging Code
- GitHub Exam
You can install Git Bash using Chocolatey, a package manager for Windows. If you haven't installed Chocolatey yet, run the following command in PowerShell with administrative privileges:
Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = `
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Then, install Git and VS Code:
choco install git.install
choco install vscode
git --version
#check where oyu are?
pwd
#All files & folders
ls
#The folder tracked by git or not ?
git status
docs |
---|
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --list
Main Folder
│
│── Folder 01
└── Folder 02: I want to track this folder
cd Folder 02
git status
git init
Py Projects
Main Folder
│
│── Folder 01
└── Folder 02
│
└── .git: ⚠️
git clone https://github.com/username/repository.git
git status
Here’s a comprehensive table summarizing the states and their short indicators in Git, along with descriptions:
UU
for a file that is unmerged with conflicts.AA
,DD
, etc., for specific merge conflict cases (e.g., both sides added or deleted a file).
touch "file 01" "file 02"
Py Projects
Main Folder
│
│── Folder 01
└── Folder 02
│
│── .git:
│── file 01
└── file 02
# git add filename_01.txt filename_02.txt
git add .
Use git add .
to add all changes.
git commit -m "1st commit"
Again Use git add .
to add all changes.
git add filename_02.txt
git commit -m "2nd commet after modified a file"
⚠️ ⚠️ ⚠️ VS-code & Web-editor ❌ Merge Conflicts ⚠️ ⚠️ ⚠️ 
⚠️ I have a github propository in the github. And I clone this repository using http URL, so I directly push my all changes through VS code. But what happened eat I open Github web editor and modify any file and push from it. This time how to sync my geethab with vs code in this two cases - case1 - if my I not work on vs good and there was no modified or changes. And in case2 - what happened I update from GitHub web editor but there was also some modification exist in v.s code which is comet but not push ⚠️
To synchronize your local repository (in VS Code) with the remote GitHub repository in both cases, follow these steps:
You updated a file in the GitHub web editor, but no changes were made in your local repository.
-
Pull the Latest Changes:
- Open the terminal in VS Code or use the Source Control tab.
- Run:
git pull origin <branch_name>
- Replace
<branch_name>
with the branch you are working on (e.g.,main
ormaster
).
-
Confirm Sync:
- After pulling, your local repository will now match the remote repository since there were no local changes to cause a conflict.
You updated a file in the GitHub web editor and also made changes locally that are committed but not pushed.
-
Pull the Latest Changes:
- First, fetch and merge the remote changes using:
git pull origin <branch_name>
- First, fetch and merge the remote changes using:
-
⚠️ Resolve Merge Conflicts (if any):- If there are conflicts between the changes made locally and those from the GitHub web editor, Git will indicate the files with conflicts. Resolve these conflicts by:
- Opening the conflicted files in VS Code.
- Looking for conflict markers (
<<<<<<<
,=======
,>>>>>>>
). - Deciding whether to keep your changes, the remote changes, or both.
- After resolving the conflicts, stage the resolved files:
git add <file_name>
- Commit the resolved changes:
git commit -m "Resolved merge conflicts"
- If there are conflicts between the changes made locally and those from the GitHub web editor, Git will indicate the files with conflicts. Resolve these conflicts by:
-
Push Your Changes:
- Once the merge is complete and there are no conflicts, push your changes back to the remote repository:
git push origin <branch_name>
- Once the merge is complete and there are no conflicts, push your changes back to the remote repository:
- Always pull the latest changes before starting work in VS Code to minimize conflicts.
- Use
git status
frequently to check the state of your repository and understand whether changes are staged, unstaged, or committed. - If you only want to review the changes made in the GitHub web editor before pulling, use:
git fetch origin <branch_name> git log origin/<branch_name>
Once you've committed your changes locally, use the git push
command to push those changes to a remote repository.
Syntax:
git push <remote_name> <branch_name>
Example:
git push origin main
Replace origin
with the name of your remote repository, and main
with the name of the branch you're pushing to.
If it's your first time pushing to the remote repository, you may need to set up tracking:
git push -u origin main
After the initial setup, simply use git push
for future pushes.
git push
🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥
🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥🚥
In the node-todo-cicd
directory, update the remote URL to point to your repository:
git remote set-url origin https://github.com/akashdip2001/AWS.git
Verify the change with:
git remote -v
It should now display:
origin https://github.com/akashdip2001/AWS.git (fetch)
origin https://github.com/akashdip2001/AWS.git (push)
-
Create the directory structure in your repository:
mkdir -p Projects/CI-CD/Project\ 001 mv * Projects/CI-CD/Project\ 001/
-
Ensure no unnecessary files (e.g.,
.git
from the original project) are moved:rm -rf Projects/CI-CD/Project\ 001/.git
-
Add the new directory and its content to the staging area:
git add Projects/CI-CD/Project\ 001/
-
Commit the changes with an appropriate message:
git commit -m "Added node-todo-cicd project to Projects/CI-CD/Project 001"
Push the changes to your repository on GitHub:
git push origin master
Replace master
with the branch name you're using if it differs.
- Go to your repository on GitHub: https://github.com/akashdip2001/AWS.
- Navigate to
Projects/CI-CD/Project 001
to ensure the files are correctly placed.
This method ensures the project is correctly uploaded to the desired directory in your repository.
init
- Used to create a new repository
mkdir <NewFolderName>
cd <NewFolderName>
git init
Use cd ..
to navigate back to the main folder.
mkdir
creates a new folder and cd
enters it. Then, create or edit files within the folder.
git status
git add .
git commit -m "Initial commit"
git status
git push origin main
Without a README: This allows you to clone the repository locally, initialize Git, and push all local files.
git remote add origin https://github.com/username/repository.git
git remote -v
Use git remote -v
to verify the remote connection.
git branch
If you're on the master
branch, rename it to main
.
git branch -M main
git push -u origin main
The -u
flag sets up tracking for future pushes, allowing you to use git push
without specifying the remote and branch.
git status
git add .
git commit -m "Add new file or update"
git push
git branch
#git branch -M main
git branch -m <old-branch-name> <new-branch-name>
git branch <new-branch-name>
git checkout -b <new-branch-name>
git branch
# create new Branch Then switch
git branch <branch-name>
git switch <branch-name>
git checkout <branch-name>
# Auto create the branct (if not exist) & switch
git switch -c <branch-name>
git branch -d <branch-name>
git status
git add .
git commit -m "Your commit message"
git push origin <branch-name>
docs |
---|
steps 
git branch
git branch "Test-Share-link"
git switch "Test-Share-link"
git branch
git status
git add .
git commit -m "add Test-Share-link .md file"
# ❌ git push
# ✅
git push --set-upstream origin Test-Share-link
create a Project Locallyt with branch name master
and 🔵 want to upload a existing Repo with `main' branch.
🟢 Normally you can push your code with master
and Marge the Branch in GitHub ⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️
“The workspace currently open doesn’t have any folders containing Git repositories.”
You want to upload this directory to your existing GitHub repo:
👉 https://github.com/akashdip2001/Arduino-IDE-setup
Follow these simple steps inside VS Code terminal:
If you haven’t yet:
cd path/to/ESP8266_LED_Control
git init
git remote add origin https://github.com/akashdip2001/Arduino-IDE-setup.git
If you get an error like “remote origin already exists”, use:
git remote set-url origin https://github.com/akashdip2001/Arduino-IDE-setup.git
git add .
git commit -m "Upload ESP8266 LED Control project"
If your GitHub repo's branch is
main
:
git push -u origin main
Or if it's
master
:
git push -u origin master
Go to your repo page: github.com/akashdip2001/Arduino-IDE-setup — your files should now be uploaded 🎉
you can directly upload to the main
branch, but here’s what’s happening and how to fix it in the cleanest way:
- Your local branch is named
master
by default. - Your GitHub repo (
https://github.com/akashdip2001/Arduino-IDE-setup.git
) has themain
branch (notmaster
). - When you tried
git push origin main
, Git said:
error: src refspec main does not match any
➤ Because your local branch is still namedmaster
.
This way, you’ll align with GitHub’s default and won’t create extra branches.
git branch -m master main
git push -u origin main
Done! Now you’re working with the main
branch directly, just like your GitHub repo. ✔️
If you don't want to rename the local branch but still push it to main
on GitHub:
git push -u origin master:main
This tells Git: “Push my local master
branch to the remote main
branch.”
To always start your new projects with a main
branch locally, you can set this globally:
git config --global init.defaultBranch main
This avoids the master
vs main
mix-up in the future. ✅
This is just a small sync issue between your local main
branch and the remote main
branch on GitHub.
The remote main
branch already has some commits (probably a README or .gitignore
added through GitHub's UI), but your local main
doesn't have them. So Git is blocking your push to avoid overwriting remote history.
Here’s the step-by-step:
- Pull remote
main
first and merge
git pull origin main --allow-unrelated-histories
- The
--allow-unrelated-histories
flag helps when your local repo and the GitHub repo were initialized separately. - You may be asked to enter a merge commit message. Just accept it (save and close the editor).
git push -u origin main
Boom 💥! Now your local project is successfully pushed to GitHub’s main
branch.
To avoid this in future projects:
- Create the repo on GitHub without any files (uncheck README, .gitignore, License).
- Or initialize your local repo first, then push, and GitHub won’t have conflicts.
⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️⚙️
#git diff <branch-name> # Compare commits, branches, files & more
git merge <branch-name>
git pull origin main # Download and synchronize with GitHub
📄 Documentation | ![]() |
---|