Git Flow
From git add to git push
Basic Flow
Starting from zeror
1. Initialize any dir as local git repo
[x@archlinux Git-Learn]$ git init
Initialized empty Git repository in /home/x/Documents/code-related-stuff/code-learning/Git-Learn/.git/
2. Create some files
These files will be in Working dir (Untracked)
# this is cat command it lets you create a file and write in it quickly
# When you complete writing just press CTRL+D to save and exit.
[x@archlinux Git-Learn]$ cat > first_file.txt #command `cat >` to create a file
Hello this is my first file, i am writing it using cat > Command.
[x@archlinux Git-Learn]$ ls # command - `ls` - to list files
first_file.txt
[x@archlinux Git-Learn]$ cat first_file.txt # command `cat` to read content of a file
Hello this is my first file, i am writing it using cat > Command.
3. Check Git status
Untracked files matlab - Ye files Working dir me nayi aayi hai ya pahle ke files ko modify kiya gaya hai to wo ab working dir me aa gayi
[x@archlinux Git-Learn]$ git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
first_file.txt
nothing added to commit but untracked files present (use "git add" to track)
4. Move files from working dir to Stagging area
Jab decide ho jaaye ki kis kis file ko stagging next commit me rakhna hai tab ye kar do
Syntax:
For single file: git add filename>
For multiples: git add <file1> <file2> ...
For all file in working dir: git add .
[x@archlinux Git-Learn]$ git add first_file.txt
[x@archlinux Git-Learn]$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: first_file.txt
5. Now You can commit files
When you do git commit - Git saves a complete snapshot of all the files in the staging area at the time of the commit
# first let's check status
# changes to be commited - ye files staged ho gayi hai ab inko hi commit kiya jaayega
[x@archlinux Git-Learn]$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: first_file.txt
new file: sec.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
x.txt
use below command to commit,
- -m "your Commit message" ka use aap commit message dene ke liye kar sakte ho
[x@archlinux Git-Learn]$ git commit -m "two file commited"
[main (root-commit) 86b8ab3] two file commited
2 files changed, 2 insertions(+) # 2 file change hua hai aur, 2 line add hui hai
create mode 100644 first_file.txt
create mode 100644 sec.txt
[x@archlinux Git-Learn]$ git status
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
x.txt
nothing added to commit but untracked files present (use "git add" to track)
[x@archlinux Git-Learn]$
- phir se status dekhne par dikh raha hai ki untracked file yani working dir wali file commit nahi hui hai bas stagged files hi commit hui hai
Let's check what commit we have done
use git log command, this commands gives you
- Commit id: 86b8ab38c026e9a4a11052a8c8b39a58418f62bd,
- Branch info of commit
- Author details (Name & mail)
- Timestamp of commit
- Commit message
[x@archlinux Git-Learn]$ git log
commit 86b8ab38c026e9a4a11052a8c8b39a58418f62bd (HEAD -> main)
Author: rishabh679 <me.rishabhh.com>
Date: Mon Jan 26 23:46:52 2026 +0530
two file commited
You can use git show commit-id command to see the commited code
[x@archlinux Git-Learn]$ git show 86b8ab38c026e9a4a11052a8c8b39a58418f62bd
commit 86b8ab38c026e9a4a11052a8c8b39a58418f62bd (HEAD -> main)
Author: rishabh679 <me.rishabhh.com>
Date: Mon Jan 26 23:46:52 2026 +0530
two file commited
diff --git a/first_file.txt b/first_file.txt
new file mode 100644
index 0000000..5d21a70
--- /dev/null
+++ b/first_file.txt
@@ -0,0 +1 @@
+Hello this is my first file
diff --git a/sec.txt b/sec.txt
new file mode 100644
index 0000000..5d21a70
--- /dev/null
+++ b/sec.txt
@@ -0,0 +1 @@
+Hello this is my first file
[x@archlinux Git-Learn]$
6. Now I want to save this code in Remote repo
Connect your local repo to Remote repo
Kyoki bina connect kiye tumhare machine ko kaise pata chalega ki code kaha upload karna hai?
git remote add name_of_remote_repo <server>
git remote add origin https://github.com/rishabh679/langchain-by-eden-marco-udemy-2025-10-20.git
we can also do -> $ git remote add my_github_remote https://github.com/rishabh679/langchain-by-eden-marco-udemy-2025-10-20.git
- So jab ham push karenge to iss name_of_remote_repo ka use aayega ki kaha kaun si repo me push karna hai kyoki ham bahot sare remote repo add kar sakte hai
- Yaha par bas hamne ye kiya ki apane remote repo ko add kiya apane local repo me aur repote repo ka address ka ek alias name de diya name_of_remote_repo
- You can use below command to list all remote repo which are configured in your local repo
git remote -v
[x@archlinux Web-4-Notes]$ git remote -v
my_github https://github.com/rishabh679/web4notes.git (fetch)
my_github https://github.com/rishabh679/web4notes.git (push)
Now It is time to push karte hai
When you execute git push, all the commits from your local branch that are not present in the remote repository are uploaded, not just the single last commit
SYNTAX - $ git push name_of_remote_repo branch_name
-branch_name (kis branch ko push karna hai uska naam yaha aayega)
-agar ye branch github pe nahi hoga to create ho jaayega, hoga to ussi me...
git push origin main
git push -u origin <branch-name>
- push and set tracking(recommended for new branches)
[x@archlinux basics-interesting-fact-about-peoples]$ git push -u origin main
Enumerating objects: 8, done
7. Pull Code from Remote repo
Agar aapka remote repo aapke local repo se aage chal raha hai to updated cheeje aapke local repo me aa jaayengi, aur agar aap remote repo se aage chal rahe ho to kuch nahi aayega