š Getting Started with Git and GitHub: A Beginnerās Guide
Source: Dev.to
What and Why: Git vs. GitHub
- Go back to earlier versions if something breaks.
- Work with teammates without overwriting each otherās work.
- See who made what changes and when.
GitHub is a cloudābased platform that hosts Git repositories, providing additional tools for collaboration, issue tracking, and code review. It offers remote repository hosting and integrates with Git for easier teamwork.
Your First Steps: Setting Up a Project
1. Tracking changes
git init # Initialize a new repository
git status # See untracked or modified files
git add # Stage selected changes
git commit -m "Message" # Create a snapshot with a descriptive label
2. Pushing code to GitHub
-
Create a new repository on GitHub.com.
-
Copy the repository URL, e.g.
https://github.com/your-username/my-project.git. -
Link your local folder to the remote (run once):
git remote add origin https://github.com/your-username/my-project.git -
Push your code:
git push -u origin main
3. Pulling code from GitHub
git pull origin main
Basic Workflow Summary
-
Create a new repository on GitHub via the web interface.
-
Clone it to your machine:
git clone https://github.com/your-username/my-project.git -
Make changes in the working directory.
-
Stage changes:
git add . -
Commit with a message:
git commit -m "Describe your changes" -
Push to GitHub:
git push -u origin main
Happy coding, and may your code always be perfectly versionācontrolled! āØš»