Using Git
GitHub is a powerful platform for version control and collaboration, allowing developers to work together on projects from anywhere in the world. It utilizes Git, a widely used version control system, to track changes in code and manage projects effectively. This tutorial will guide you through the basics of using GitHub, from setting up your account and installing Git to creating repositories and collaborating with others. Whether you’re a beginner or looking to refresh your skills, this guide will help you get started on both Windows and Linux.
Here is a very good detailed tutorial if you want to skip reading the rest of the tutorial.
Create a GitHub Account
- Go to GitHub.
- Click on “Sign up” in the top right corner.
- Fill in the required information (username, email, password) and follow the prompts to create your account.
- Check your email inbox for a verification email from GitHub and follow the instructions to verify your account.
Set up Git
For Windows Users:
- Download the Git installer for Windows from git-scm.com.
- Run the installer and follow the setup instructions, accepting the default options unless you have specific preferences.
For Linux Users:
Open a terminal.
Install Git using your package manager. For example, on Ubuntu, you can run:
sudo apt update sudo apt install git
Configure Git
Linux users use Terminal and Windows users use Powershell.
Set your username and email:
git config --global user.name "Your Name" git config --global user.email "your_email@example.com"
Create a New Repository
- Log into GitHub and click on the “+” icon in the top right corner.
- Select “New repository.”
- Fill in the repository name, description (optional), and choose to make it public or private.
- Click “Create repository.”
Set Up a Local Repository
Open a terminal/powershell and navigate to the directory where you want to create your project:
cd /path/to/your/directory
Create a new directory for your project:
mkdir my-project cd my-project
Initialize a Git repository:
git init
Add Files and Make Your First Commit
Create a new file (e.g.,
README.md
) using a text editor or the terminal:echo "# My Project" >> README.md
Add the file to the staging area:
git add README.md
Commit the changes with a message:
git commit -m "Initial commit"
Connect Local Repository to GitHub
Link your local repository to the GitHub repository:
git remote add origin https://github.com/your_username/my-project.git
Push your commits to GitHub:
git push -u origin master
Making Changes and Collaborating
Edit files using a text editor of your choice (Notepad, Visual Studio Code, Vim, Nano, etc.).
Stage and commit your changes:
git add . git commit -m "Updated the README"
Push your changes to GitHub:
git push
To collaborate with others, you can fork repositories, create branches, and submit pull requests:
Fork a Repository: Click the “Fork” button on a repository to create your own copy.
Create a Branch:
git checkout -b new-feature
Submit a Pull Request: After pushing your branch, go to the original repository on GitHub and create a pull request.
Managing Your Repository
- Go to your repository on GitHub to see your files, commits, branches, and issues.
- Create issues to track tasks or bugs.
- Use the Projects feature to organize and prioritize your work.
- Automate workflows using GitHub Actions to build, test, and deploy your projects.