GitHub is one of the most used platforms for source code management and developer collaboration. In this guide, we will see how to create a repository, add collaborators, upload code and make the first commit.
🔗 Do you like Techelopment? Check out the site for all the details!
Creating a Repository on GitHub
- Log in to your GitHub account (or register if you don't have one - you can find a guide in the article How to Create an Account on GitHub) at GitHub.
- If this is your first repository, click on the "Create repository" button at the top left, otherwise if you have already created a repository, you will find the "New" button at the top left.
- Enter a name for the repository in the "Repository name" field.
- (Optional) Add a description.
- Choose whether to make the repository Public or Private.
- (Recommended) Select "Add a README file" to include a README file.
- (Optional) Add a .gitignore file and select a license.
- Click on "Create repository".
Adding a Collaborator
If you want to collaborate with other people, you can add a collaborator to the repository:
- Go to the repository you created.
- Click on "Settings".
- In the side menu, go to "Collaborators".
- Click on "Add people".
- Enter the collaborator's username or email.
- Click on "Add collaborator" and confirm.
The collaborator will receive an email to accept the invitation.
Cloning the Repository Locally
Now that the repository is ready, you can clone it on your computer to work on the code:
- First we need to install the git client on the computer, you can download it here https://git-scm.com/downloads
- After installing git, you can go back to GitHub and copy the repository URL (you can find it on the main page of the repo, by clicking on "Code" > HTTPS).
- Choose a folder where you want to clone the repository (e.g. C:\my_folder), open the terminal or command prompt in this folder and type:
git clone <url_of_repository
If the repository is public you will not be asked for any authentication otherwise you will have to authenticate. Let's see the two cases in detail.
Cloning a public repository
If the repository you are cloning is public then cloning will happen automatically via the git clone command and you will immediately have the newly cloned folder available.
Cloning a private repository
If the repository is private, you must authenticate. There are several options:
A. Using HTTPS credentials (Personal Token)
GitHub has deprecated the use of passwords for HTTPS, so you need to generate a Personal Access Token (PAT):
- Go to GitHub > Settings > Developer Settings > Personal Access Tokens.
- Generate a new token with repo permissions.
- Use the following command to clone the repository, replacing TOKEN with your token:
git clone https://TOKEN@github.com/username/repository.git
B. Using SSH (recommended method)
If you prefer to authenticate with SSH:
- Generate an SSH key on your computer with:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Add the public key (id_rsa.pub) to your GitHub account in Settings > SSH and GPG keys.
- Clone the repository with:
git clone git@github.com:username/repository.git
Public or private, at this point you will have the local repository on your computer. 😊
Adding and Uploading Code
If you have created new files or modified existing ones, you can add and upload them to the repository:
- Add the files to Git tracking:
git add.
- Create a commit with a descriptive message:
git commit -m "Changes description"
- Send the commit to the remote repository:
git push origin main
(If you have a branch other than "main", replace with your branch name.)
Follow me #techelopment
Official site: www.techelopment.it
Medium: @techelopment
Dev.to: Techelopment
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
youtube: @techelopment
whatsapp: Techelopment
Top comments (0)