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
ποΈ 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
π Stages 24MCR080-NOTEPAD.txt
so it's ready to be committed.
β Commit the File
git commit -m "Added Personal Details"
π Creates a snapshot of your project with a commit message.
π Check Git Status
git status
π View which files are staged, modified, or untracked.
π View Commit Log
git log
π Shows the history of your commits.
π Add a Remote GitHub Repository
git remote add origin https://github.com/rajaramnivas/24MCR080.git
π Links your local repository to a GitHub remote.
πΏ Check Current Branch
git branch
π§Ύ Displays your current branch, typically master
by default.
πͺ Rename master
to main
(Optional but Recommended)
git branch -M main
π― Renames the current branch to main
for consistency with modern standards.
βοΈ Push Code to GitHub (First Time)
git push -u origin main
π€ 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:
π 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
π 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)
Helpful Content
Useful
congrats Rajram