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!