Table of content:
- Definition
- Requirements
- Creating a new Repository
- Maintaining a Repository
- Fork the repository
- Clone the repository
- Create a branch
- Initializing a repository
- Adding files to the repository
- Make an Initial Commit
- Push changes to your repository
- Pull requests
- Renaming a repository
- Transferring a repository
- Deleting a repository
- Restoring a deleted repository
-
Conclusion
- Useful resources
Definition
GitHub is a web-based tool for version control and collaboration. It provides developers with an easy-to-use interface for creating repositories (remote storage sites), tracking code changes over time (version control), and collaborating on projects with others.
Requirements
- GitHub Account
- Git Installed
- Text Editor or IDE
- Basic Command Line Skills
- Creating a new repository
As a prerequisite you need a GitHub account to be able to create a repository.
Creating a GitHub account
- Navigate to https://github.com/.
- Click Sign up.
- Follow the prompts to create your personal account.
During sign up, you'll be asked to verify your email address. Without a verified email address, you won't be able to complete some basic GitHub tasks, such as creating a repository.
If you're having problems verifying your email address, there are some troubleshooting steps you can take. For more information, see "Verifying your email address."
Creating a new repository from the web UI
step 1-;
Once you have GitHub account, In the upper-right corner of your page, click the + sign .
Step 2-:
On the drop down list, click on the New repository option.
Step 3-;
Use the Owner drop-down menu to choose the account that will own the repository.
step 4-:
In the repository name field, enter a name for your repository and optionally provide a description. Select the desired repository visibility, then click the "Create repository" button at the bottom of the page.
For example-;
Step 5-;
At this point, you have successfully created a new repository using the web UI.
- Maintaining a Repository
- Fork the repository
Fork the repository by clicking the fork button on the top of the page. This will create an instance of that entire repository in your account.
- Clone the repository
To work with the repository locally, clone it to your machine. Click on the "Code" button and copy the provided link.
Open the terminal and run the following command. It will clone the repository locally.
$ git clone [HTTPS ADDRESS]
For example
$ git clone hhtps://github.com/ThanoshanMV/articles-of-the-week.git
Now we have set up a copy of the master branch from the main online project repository.
$ cd [NAME OF REPOSITORY]
- Create a branch
It’s good practice to create a new branch when working with repositories, whether it’s a small project or contributing to a group's work.
Branch name should be short and it should reflect the work we’re doing.
Now create a branch using the git checkout
command:
$ git checkout -b [Branch Name]
- Initializing a repository:
To initialize a new Git repository, open the terminal, navigate to the root directory of your project, and execute git init. This command initializes an empty Git
repository in the specified directory and generates a .git sub-directory that contains versioning information.
- Adding files to the repository
Make essential changes to the project and save it.
Then execute git status
, and you’ll see the changes.
Use the git add
.
command to add your project files to the repository after it has been initialized. For instance, you may use git add . to add all files in the repository. The files are ready to be included in the subsequent commit at this point.
- Make an Initial Commit
Use the git commit -m "Initial commit message"
command to generate an initial commit once you have added the required files. Commits are a snapshot of the project at a particular moment in time and ought to have a detailed message detailing the modifications that were made.
- Push changes to your repository
In order to push the changes to GitHub, we need to identify the remote’s name.
$ git remote
For this repository the remote’s name is “origin”.
After identifying the remote’s name we can safely push those changes to GitHub.
- On GitHub.com, navigate to the main page of the repository.
- Above the list of files, click Code.
- To clone your repository using the command line using HTTPS, under "Quick setup", copy link . To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click SSH, then copy link .
- Open Terminal .
- Change the current working directory to the location where you want the cloned directory.
git push origin [Branch Name]
- Pull requests
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.
- Renaming a repository
- On GitHub.com, navigate to the main page of the repository.
- Under your repository name, click Settings. If you cannot see the "Settings" tab, select the drop-down menu, then click Settings.
- In the Repository Name field, type the new name of your repository.
Click Rename.
- Warning: If you create a new repository under your account in the future, do not reuse the original name of the renamed repository. If you do, redirects to the renamed repository will no longer work.
- Transferring a repository
- When you transfer a repository that you own to another personal account, the new owner will receive a confirmation email. The confirmation email includes instructions for accepting the transfer. If the new owner doesn't accept the transfer within one day, the invitation will expire.
- On GitHub.com, navigate to the main page of the repository.
- Under your repository name, click Settings. If you cannot see the "Settings" tab, select the drop down menu, then click Settings.
1. At the bottom of the page, in the "Danger Zone" section, click Transfer.
-
Read the information about transferring a repository, then under "New owner", choose how to specify the new owner.
- To choose one of your organizations, select “Select one of my organizations.” - Select the drop-down menu and click an organization. - Optionally, in the "Repository name" field, type a new name for the repository. - Note: You must be an owner of the target organization to rename the repository. - To specify an organization or username, select Specify an organization or username, then type the organization name or the new owner's username.
Read the warnings about potential loss of features depending on the new owner's GitHub subscription.
Following “Type Repository Name to confirm”, type the name of the repository you'd like to transfer, then click I understand, transfer this repository.
Deleting a repository
On GitHub.com, navigate to the main page of the repository.
Under your repository name, click Settings. If you cannot see the "Settings" tab, select the drop-down menu, then click Settings.
- On the "General" settings page (which is selected by default), scroll down to the "Danger Zone" section and click Delete this repository.
- Click I want to delete this repository.
- Read the warnings and click I have read and understand these effects.
- To verify that you're deleting the correct repository, in the text box, type the name of the repository you want to delete.
- Click Delete this repository.
- Restoring a deleted repository
Some deleted repositories can be restored within 90 days of deletion.
In the upper-right corner of any page, click your profile photo, then click Settings.
In the "Code planning, and automation" section of the sidebar, click Repositories.
Under "Repositories", click Deleted repositories.
Next to the repository you want to restore, click Restore.
Read the warning, then click I understand, restore this repository.
- Conclusion
Repositories on GitHub are an effective tool for organizing and working together on software projects. Developers may assure project transparency and version control, promote teamwork, and expedite workflows by adhering to best practices when creating, organizing, and managing repositories. Leveraging GitHub repository capabilities can greatly improve code quality and efficiency, whether working on a team project or a personal one.
- Useful Resources
Official GitHub Documentation
- GitHub Docs: https://docs.github.com/en
- Creating a repository: https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository
- Managing repositories: https://docs.github.com/en/repositories
Git and GitHub Learning Resources
- Git Handbook: https://guides.github.com/introduction/git-handbook/
- GitHub Learning Lab: https://lab.github.com/
- Git & GitHub Crash Course for Beginners (Video): https://www.youtube.com/watch?v=RGOj5yH7evk
Tutorials and Guides
- GitHub Guides: https://guides.github.com/
- GitHub Skills: https://skills.github.com/
- FreeCodeCamp GitHub Tutorial: https://www.freecodecamp.org/news/git-and-github-for-beginners/
Books
- "Pro Git" by Scott Chacon and Ben Straub (free online book): https://git-scm.com/book/en/v2
- "GitHub For Dummies" by Sarah Guthals and Phil Haack
Community and Forums
- GitHub Community: https://github.community/
- Stack Overflow (GitHub tag): https://stackoverflow.com/questions/tagged/github
Top comments (3)
This the best article so far i have read. To whoever who worked on this thank you
Wow! so insightful.
Great article!