Tools: A Beginner's Guide to Git and GitHub

Tools: A Beginner's Guide to Git and GitHub

Source: Dev.to

What is git If you have ever saved a file as final_project.py, then final_project_v2.py, and eventually final_project_v3.py, you have experienced the manual version of version control. It’s messy, confusing, and prone to errors. In this article I will show how through using Git and Github you can also manage your code as a professional. Git is a version control system that tracks every change you make to your files. This allows you to Collaborate: Multiple people can work on the same project without overwriting other's code. Undo mistakes: Revert to a previous version if your code breaks Experiment: Create a branch to try out a new feature without interfering with the main project Github,on the other hand, is a website that hosts your Git repositories in the cloud while Git is the tool on your computer. 1. Tracking Changes Using Git Before you can send code to GitHub, you need to track it locally. The Git workflow follows a simple three-step process: Modify → Add → Commit. Step A: Initialize your project Open your terminal in your project folder and run: git init This creates a hidden folder that starts tracking your files. Step B: The Staging Area When you change a file, Git notices, but it doesn't save it automatically. You must "stage" the files you want to include in your next snapshot: Step C: The Commit A commit is a permanent snapshot of your staged changes. Always include a descriptive message: git commit -m "Add login functionality" 2. Pushing Code to GitHub Once you have committed your changes locally, you want to upload them to the cloud (GitHub) so they are backed up and viewable by others. Create a Repository: Go to GitHub and click New Repository. Give it a name and click Create. Link your local Git to GitHub: Copy the URL of your new repo and run: git remote add origin https://github.com/your-username/your-repo-name.git git push -u origin main The "Pull" Command This command fetches the latest version of the code from GitHub and automatically merges it into your local files: Version control might feel like extra work but it's the ultimate safety net for devs. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK: git add filename.py Or to add everything: git add . Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: git add filename.py Or to add everything: git add . COMMAND_BLOCK: git add filename.py Or to add everything: git add . - Collaborate: Multiple people can work on the same project without overwriting other's code. - Undo mistakes: Revert to a previous version if your code breaks - Experiment: Create a branch to try out a new feature without interfering with the main project - Pulling Code from GitHub If you are working in a team, or if you are working from a different computer, you need to pull the latest changes from GitHub to your local machine.