DEV Community

Cover image for # πŸš€ Step-by-Step Git Commands for Beginners (with Visuals)
Rajaram Nivas
Rajaram Nivas

Posted on

# πŸš€ Step-by-Step Git Commands for Beginners (with Visuals)

If you're just getting started with Git and GitHub, here's a simple, clear guide to walk you through setting up your repository and pushing your changes for the first time!


πŸ› οΈ Initialize a Git Repository

git init
Enter fullscreen mode Exit fullscreen mode

πŸ—‚οΈ This creates a new Git repository in your current folder.

Example: initializing in a folder named 24MCR080.


πŸ“„ Add a File to the Staging Area

git add 24MCR080-NOTEPAD.txt
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Stages 24MCR080-NOTEPAD.txt so it's ready to be committed.


βœ… Commit the File

git commit -m "Added Personal Details"
Enter fullscreen mode Exit fullscreen mode

πŸ“ Creates a snapshot of your project with a commit message.


πŸ” Check Git Status

git status
Enter fullscreen mode Exit fullscreen mode

πŸ‘€ View which files are staged, modified, or untracked.


πŸ“œ View Commit Log

git log
Enter fullscreen mode Exit fullscreen mode

πŸ“š Shows the history of your commits.


🌐 Add a Remote GitHub Repository

git remote add origin https://github.com/rajaramnivas/24MCR080.git
Enter fullscreen mode Exit fullscreen mode

πŸ”— Links your local repository to a GitHub remote.


🌿 Check Current Branch

git branch
Enter fullscreen mode Exit fullscreen mode

🧾 Displays your current branch, typically master by default.


πŸͺ„ Rename master to main (Optional but Recommended)

git branch -M main
Enter fullscreen mode Exit fullscreen mode

🎯 Renames the current branch to main for consistency with modern standards.


☁️ Push Code to GitHub (First Time)

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

πŸ“€ Pushes the main branch to GitHub and sets it as the default upstream branch.


πŸ–ΌοΈ Visuals for Reference

Here are some screenshots that help illustrate the steps:

Git Init & Add

Git Commit

Git Push


πŸ” Modifying or Adding New Files

When you update existing files or add new ones, repeat the following:

git add .
git commit -m "Your updated message"
git push origin main
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ This ensures all changes are tracked and synced with your GitHub repo.


🎯 Conclusion

And that’s it! You’ve successfully:

  • Initialized a Git repo
  • Committed your work
  • Connected to GitHub
  • Pushed your project to the cloud! ☁️

Top comments (3)

Collapse
 
selva_j profile image
Selva

Helpful Content

Collapse
 
viratpk18 profile image
Praveen Kumar

Useful

Collapse
 
nisanth_gurusamy_620db52b profile image
Nisanth Gurusamy

congrats Rajram