DEV Community

Selva
Selva

Posted on

GITHUB commands

Step-by-Step Git Commands Execution:

Initialize a Git repository:
git init
Creates a new Git repository in the folder 24MCR095.

Add a file to staging area:
git add 24MCR095.txt
Adds 24MCR095.txt to the staging area.

Commit the file:
git commit -m "Added Personal Details"
Creates a commit with the message "Added Personal Details".

Check Git status:
git status
Shows that 24MCR095.txt has been modified but not staged.

View commit log:
git log
Displays the commit history (one commit at this point).

Add remote GitHub repository:
git remote add origin https://github.com/selva192003/24MCR095.git
Links the local repository to a remote GitHub repo.

Check current branch:
git branch
Shows the current branch is master.

Rename branch from master to main:
git branch -M main
Renames the current branch to main.

Set Git global config for email and username:
git config --global user.email "[email protected]"
git config --global user.name "selva192003"

Sets your global Git identity.

Push code to remote repo for the first time:
git push -u origin main
Pushes the main branch to GitHub and sets upstream tracking.

Sample Screenshots:

Image description

Image description

Image description

Image description

Then , Again We will Modify or add new file means we need to follow the same steps, like

git add .
git commit -m “message”
git push origin main
Enter fullscreen mode Exit fullscreen mode

Git Commands used in this session:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git init
git clone <repo_url>
git status
git add <file>
git add .
git commit -m "Your message"
git branch
git branch <branch_name>
git checkout <branch_name>
git checkout -b <branch_name>
git pull origin <branch_name>
git push origin <branch_name>
git merge <branch_name>
git rebase <branch_name>
git restore <file>
git reset --soft HEAD~1
git reset --hard HEAD~1


Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
viratpk18 profile image
Praveen Kumar

Helpful content

Collapse
 
rajaram_nivas profile image
Rajaram Nivas

useful content

Collapse
 
vashantha_kumarks_f50a2 profile image
VASHANTHA KUMAR K.S

Good Contant