DEV Community

VASHANTHA KUMAR K.S
VASHANTHA KUMAR K.S

Posted on

Mastering Git Basics: A Beginner's Guide with Practical Commands

Git is an essential tool for every developer. Whether you're just starting or need a quick refresher, this blog will walk you through the foundational Git commands with practical examples.


๐Ÿ”ง Step-by-Step Git Commands Execution

๐Ÿงฑ 1. Initialize a Git repository

git init
Creates a new Git repository in the folder 24MCR124.

๐Ÿ“ฅ 2. Add a file to the staging area

git add 24MCR124.txt
Adds 24MCR124.txt to the staging area.

๐Ÿ’พ 3. Commit the file

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

๐Ÿง 4. Check Git status

git status
Displays changes in your working directory and staging area.

๐Ÿ“œ 5. View commit log

git log
Shows the history of commits made.

๐ŸŒ 6. Add remote GitHub repository

git remote add origin https://github.com/vashanth-kumar/24MCR124.git
Links your local repo to the GitHub remote repo.

๐ŸŒฟ 7. Check current branch

git branch
Displays the current branch. Initially it's master.

๐Ÿงพ 8. Rename branch from master to main

git branch -M main
Renames the master branch to main.

๐Ÿ‘ค 9. Set Git global config

git config --global user.email "[email protected]"
git config --global user.name "vashanth-kumar"
Sets your Git identity globally.

๐Ÿš€ 10. Push code to remote repo

git push -u origin main
Pushes your changes to GitHub for the first time and sets upstream tracking.

๐Ÿ” Pushing Additional Changes
Whenever you modify or add new files:

git add .
git commit -m "Your update message"
git push origin main

โœ… Conclusion
Mastering these basic Git commands sets the foundation for version control and collaboration in software development. Happy coding!

Image description

Image description

Top comments (3)

Collapse
 
nevodavid profile image
Nevo David

this is super helpful for anyone starting out, honestly i wish i had something this clear back then. you ever wonder if simple tools like git actually make things easier long run, or just add another layer to deal with?

Collapse
 
sachin_s24mcr084 profile image
Sachin S 24MCR084

Superub

Collapse
 
selva_j profile image
Selva

useful content