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!
Top comments (3)
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?
Superub
useful content