What is GitHub ?
GitHub is a Git repository hosting service, but it adds many of its own features. While Git is a command-line tool, GitHub provides a Web-based graphical interface.
Creating a GitHub Account
Go to this Link in a web browser. Enter your details and create your account. For more details and a step-by-step guide, visit this wikihow page
Making your first repository and your first commit
Follow this guide to create a new repository
Congratulations! You have now created a repository, including a README file, and created your first commit on GitHub.
Now let's work with remote repositories on our local machine.
Forking a Repository
You might fork a project to propose changes to the upstream, or original, repository. In this case, it's good practice to regularly sync your fork with the upstream repository.
Follow these steps:
On GitHub, navigate to the desired repository, example repo
In the top-right corner of the page, click Fork.
Congratulations! You now have your own copy of the forked repository.
Cloning the Forked Repository
On GitHub, navigate to your copy of the forked repository. The name of the repo will be of format Your-Usename/repo-name.
Above the list of files, click Code.
To clone the repository using HTTPS, under "Clone with HTTPS", click the copy button. To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click Use SSH, then click the copy button. To clone a repository using GitHub CLI, click Use GitHub CLI, then click the copy button.
Open Terminal/Git Bash.
Change the current working directory to the location where you want the cloned directory.
Type
git clone
, and then paste the URL you copied earlier. It will look like this, with your GitHub username instead ofYOUR-USERNAME:
$ git clone https://github.com/YOUR-USERNAME/repo-name
- Press Enter. Your local clone will be created.
Great!! You have created a clone of the repo on your local machine.
Adding upstream
Upstream generally refers to the original repo that you have forked.
- Check the remote repos(origin and upstream) for the clone using the command:
git remote -v
- In the output you will see two origin and two upstream repository urls the fetch and push at the end. Example:
origin https://github.com/YOUR-USERNAME/repo-name.git (fetch)
origin https://github.com/YOUR-USERNAME/repo-name.git (push)
upstream https://github.com/RepoOwner-Name/repo-name.git (fetch)
upstream https://github.com/RepoOwner-Name/repo-name.git (push)
- If you don't see upstream, add it using
git remote add upstream https://github.com/RepoOwners-Name/repo-name.git
Contributing to repository
Now create a branch using
git branch [branch-name]
Make desired changes
Stage the changes using
git add .
- Commit the staged files using
git commit -m "message-about-changes"
- Push the changes to origin repository using
git push origin [branch name]
Making a Pull Request
- On GitHub, navigate to the main page of the repository.
- In the "Branch" menu, choose the branch that contains your commits.
- Above the list of files, click Pull request
- Use the base branch dropdown menu to select the branch you'd like to merge your changes into, then use the compare branch drop-down menu to choose the topic branch you made your changes in.
- Type a title and description for your pull request.
- To create a pull request that is ready for review, click Create Pull Request. To create a draft pull request, use the drop-down and select Create Draft Pull Request, then click Draft Pull Request.
Great!! You have forked and cloned a GitHub repository and have opened a pull request in it. Now, if the repository's owner find your changes useful, they will merge your pull request.
Conclusion
We have learned:
- Making a GitHub account.
- Creating a repository.
- Forking and cloning a remote repository.
- Configuring the remotes of the repository.
- Making and pushing changes to the repository.
- Creating a pull request in the repository.