DEV Community

SAINAPEI LENAPUNYA
SAINAPEI LENAPUNYA

Posted on

DAY 2:Git & GitHub: From Local Legend to Cloud Coder ☁️

🌀 Introduction: Git Happens! So Let’s Learn It Right
You’ve written your first Django lines. Amazing! But now you're wondering:

"How do I save my project?"

"Can I go back if I break something?"

"How do people even work together on one codebase?"

Enter Git & GitHub-the superheroes of collaboration and version control.

Today, we’re going from:

“I have a folder on my Desktop” → to → “I pushed it to GitHub and my team is contributing!”

What You’ll Learn Today

Git:Tracks changes in your local files
GitHub:Hosts your code in the cloud
Forking:Copying someone else’s repo to your GitHub
Collaboration:Working together on the same codebase
Push & Pull:Sending code to GitHub, or getting it
Merge Conflicts: When code clashes and how to fix it
GitHub Issues:Tasks, bugs, to-dos all in one place
Code Review:Feedback before merging changes

Step-by-Step: Your First Git Adventure

1.🛠 Initialize Git in Your Project Folder
Go into your Django project folder and run:

git init

Enter fullscreen mode Exit fullscreen mode

This turns your folder into a Git-tracked repository.

2.Create Your .gitignore File
Tell Git to ignore certain files (like your virtual environment and cache):

touch .gitignore
Enter fullscreen mode Exit fullscreen mode

Add this inside:

env/
__pycache__/
*.pyc
*.sqlite3
Enter fullscreen mode Exit fullscreen mode

3.Add Files and Make Your First Commit

git add .
git commit -m "Initial Django project setup"
Enter fullscreen mode Exit fullscreen mode

This records your changes with a message.

4.Create a GitHub Repo
Go to github.com
Click New Repository

Image description
Name it something like my-django-app
Do not initialize with README (since we already have code)

5.Link Local Project to GitHub Repo
In your terminal:

git remote add origin git@github.com:yourusername/my-django-app.git
git branch -M main
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Boom!!! Your Django code is now live on GitHub.

6.Forking and Pull Requests (If Working With a Team)
Visit someone else’s repo

Click Fork (top right) → creates your own copy

Make changes → push them to your fork

Go back to the original repo → click New Pull Request

Add your message → submit!

⚔️Dealing With Merge Conflicts
Merge conflicts happen when:

Two people edit the same line

Git doesn’t know which to keep

When you pull and get a conflict:

Open the file

Look for:

<<<<<<< HEAD
your change
=======
their change
>>>>>>> main
Enter fullscreen mode Exit fullscreen mode

Choose one, delete the rest, then:

git add .
git commit -m "Resolved conflict"
git push
Enter fullscreen mode Exit fullscreen mode

Collaboration Tips for Beginners
✅ Always pull before pushing git pull origin main
✅ Use branches git checkout -b feature-login
✅ Write good commit messages:Helps teammates understand your work
✅ Communicate on GitHub Issues Like a shared to-do list
✅ Tag team members in PRs For code reviews

Conclusion:
You’re No Longer Just a Coder, You’re a Collaborator
Git and GitHub can feel like a mystery at first, but once you learn them, you're no longer coding alone. You're working like a professional with backups, teamwork, and confidence.

Remember keep coding, keep pushing, and don’t forget to commit to your dreams (pun intended 😄)

Top comments (0)