How to Use Git and GitHub for Version Control
How to using Git and GitHub for version control in your projects.
How to Use Git and GitHub for Version Control
Git is a version control system that helps you manage your code and collaborate with others.
Installing Git
Before using Git, you need to install it. You can install it on Linux, macOS, or Windows using the following commands:
1
2
# On Ubuntu
sudo apt-get install git
Setting Up Git
Once Git is installed, you need to configure it with your name and email:
1
2
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Creating a Repository
To create a new Git repository, navigate to your project folder and run:
1
git init
Git Commands
Staging Changes
To stage changes for commit, use:
1
git add .
Committing Changes
Once the changes are staged, commit them:
1
git commit -m "Initial commit"
Pushing to GitHub
To push your changes to GitHub, follow these steps:
- Create a new repository on GitHub.
- Link your local repository to GitHub:
1
git remote add origin https://github.com/username/repository.git
- Push your changes:
1
git push -u origin master
Conclusion
Git and GitHub are essential tools for modern software development.
This post is licensed under CC BY 4.0 by the author.