Git is a powerful distributed version control system that allows you to track changes in your code and collaborate with others. GitHub is a popular platform for hosting and sharing Git repositories. This guide will help you get started with Git and GitHub.
-
Install Git: If you haven't already, download and install Git for your operating system.
-
Create a GitHub Account: If you don't have a GitHub account, sign up for one.
Before you start using Git, configure your identity:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Replace "Your Name"
and "[email protected]"
with your name and email.
- Initialize a New Repository: Open your terminal and navigate to the project folder. Use the following command to create a new Git repository:
$ git init
- Add Files: Add the files you want to track to the repository using the following command:
$ git add .
- Commit Changes: Commit your changes with a meaningful message:
$ git commit -m "Initial commit"
-
Create a Repository on GitHub:
- Log in to your GitHub account.
- Click the "+" icon in the top right corner and select "New Repository."
- Follow the instructions to create a new repository.
-
Link Your Local Repository to GitHub:
- Use the following commands to link your local repository to the remote GitHub repository:
$ git remote add origin <repository-url>
$ git branch -M main
$ git push -u origin main
Replace <repository-url>
with the URL of your GitHub repository.
- Push Changes to GitHub:
- After making changes locally, commit them and push to GitHub:
$ git add .
$ git commit -m "Update something"
$ git push origin main
- Clone a Repository: To clone a repository from GitHub to your local machine, use the following command:
$ git clone <repository-url>
Replace <repository-url>
with the URL of the GitHub repository you want to clone.
- Create a New Branch: To work on a new feature or fix, create a new branch:
$ git checkout -b new-feature
- Make Changes and Commit: Make your changes, commit them, and push the branch to GitHub:
$ git add .
$ git commit -m "Implement new feature"
$ git push origin new-feature
- Create a Pull Request: Go to your GitHub repository, switch to the new branch, and create a pull request to merge your changes into the main branch.
- GitHub Guides: Comprehensive guides for using GitHub effectively.
- Pro Git Book: A detailed book on Git by Scott Chacon and Ben Straub.
- GitHub Learning Lab: Interactive tutorials to learn Git and GitHub.