How To Create An Account In GitHub
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
GitHub is one of the most popular and widely used code hosting platform in the world. In this blog post, we will discuss how to create an account in GitHub and getting started with GitHub.
This tutorial will cover below topis steps by steps and is intended for someone who is just getting started with GitHub.
- How to create a new account in GitHub
- How to create a repository in GitHub
- How to clone a GitHub repository in your local system
- How to setup SSH key for GitHub
- How to push changes from your local system to GitHub
- How to pull changes from GitHub to your local system
- Difference between Git Pull and Git Fetch with example
- How to create a Pull request in GitHub and more.
How To Create An Account In GitHub
Prerequisites:
- (Required) One active email id
- (Optional) One system having git installed
Step 1: Signup with GitHub.
Open your browser and navigate to below link
https://github.com/signup?source=login
Provide your preferred email id and password and complete the registration.
Step 2: Validate your email id.
One code will be sent to your email id, use that code to verify your account.
Once verified, you will be redirected to your GitHub account.
We have successfully created our first GitHub account. Next, we are going to create our first repository in GitHub. A repository in GitHub is a container to store all your files. You can create a public or privet repository in GitHub.
Step 3: Create a GitHub repository.
Click on “Create repository” to create a new repository in GitHub.
Provide a name and description to your repository, select the repository visibility to private and click “create repository”. You can also include a README file which will contain details about your repository.
- Public: Anyone on the internet can see this repository. You choose who can commit.
- Private: You choose who can see and commit to this repository.
We have successfully created our first GitHub repository.
Observe: At the top of this page, you have the URL to clone your GitHub repository using HTTPS or SSH options. Since we have created a private repository, only you can clone the repository using HTTPS or SSH.
The repository that we have just created is called a remote repository where multiple members can created/update/delete files. You can also create a local copy (local repository) of this GitHub repository by cloning this repository in your local system.
Step 4: Clone your GitHub repository using HTTPS
In the clone URL, select HTTPS and copy the URL
Open command prompt type below command
1 2 |
## Clone your GitHub repository git clone |
You will be prompted to provide access code, close the window and provide email id and password that you have used during signup with GitHub.
Don’t worry about the warning, as we have created an empty repository it giving us a warning. Next, we are going to create a file and push that into our GitHub repo.
Step 5: Push changes to GitHub
1 2 3 4 5 6 7 8 9 10 |
## Create a file cd echo "hello world" > README.md ## Add and commit the changes git add README.md git commit -m "myfile.txt added" ## Push your local changes to remote repository (GitHub) git push |
The file README.md has been pushed from our local repository to GitHub.
Refresh the GitHub page and you will be able to view the file.
GitHub allows you to access its repository using either HTTPS (using personal access token or email id and password) or SSH. We have already used HTTPS (using email id and password) method. Next, we are going to see how to generate a SSH key and setup ssh key’s in GitHub.
Step 6: Check if ssh-keygen is installed.
Open command prompt and type
1 |
ssh-keygen --help |
If You get some output, that means ssh-keygen is already present.
If ssh-keygen is not present then follow below steps to enable ssh-keygen.
Right click on windows start menu and click on “settings”.
On the settings page, click on “Apps”
Click on “Optional features”
And then click on “Add” and select “OpenSSH Client” and click “install”.
Step 7: Generate SSH Key For GitHub.
In the command prompt, type below command to generate a new SSH key pairs
1 2 3 4 |
# Generate a ssh key ssh-keygen -t rsa -b 4096 -C " # Hit enter whenever prompted |
Copy the content of your public key
Navigate to C:\ => Users => <Your_UserName> => .ssh
And copy the content of id_rsa.pub file. The other file id_rsa is your private key.
Step 8: Setup SSH Key in GitHub
Open your GitHub repository and click on your profile icon at the extreme right corner. Click on settings.
Click “SSH and GPG keys” and then click “New SSH key”
Copy the public key content inside the box next to key, provide a “Title” and click “Add SSH key”.
Navigate back to your GitHub repository and copy the repo URL for SSH
Step 9: Add a new remote repository to an existing local directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Create a new directory and get inside it mkdir mydir && cd mydir # Initialize the local repository git init # Add your github remote repository git remote add origin # Note: https url will also work the same way # Verify the remote repository git remote -v # Pull the content of remote repository git pull origin master |
Observe the README.md file has been pulled from the remote GitHub repository to your local repository. Next, we are going to create a new branch and push the changes from our local repository to GitHub repository
Step 10: Push changes from local repository to remote repository.
Create a new branch in your local repository and add some files and finally commit the changes.
1 2 3 4 5 6 7 8 9 10 |
# Create a new branch git checkout -b "branch1" # Create a file and commit the changes echo "hello world" > myfile.txt git add myfile.txt git commit -m "myfile.txt added" # Push the local branch to your remote repository git push --set-upstream origin branch1 |
If you check your GitHub repository, you will be able to find your branch and the file that you have added present in GitHub as we have pushed the changes.
Next, we are going to show how to pull from your remote repository to your local repository.
Step 11: Pulling changes from remote repository to local repository.
Navigate back to the other local repository where we have initially cloned our GitHub repo
1 2 3 4 5 |
# Navigate back to the other local repo cd .. && cd # Check the branches git branch -a |
Observe branch1 info is missing in this local repository.
Pull the changes from remote repository to local repository
1 2 3 4 5 |
# Pull the changes git pull # Check the branches git branch -a |
Observe, after the pull branch1 info has been updated in this local repository as well.
Next, we will find out what is the difference between git pull and git fetch
Step 12: Understanding the difference between git pull vs git fetch.
Update and commit some content in your GitHub repository
Navigate to your GitHub repositor and select the master branch
Click on the edit icon to edit the file inside GitHub.
Add some lines and click on “Commit changes”
Check the difference between your local master branch and remote master branch
1 2 |
# See what’s updated git diff master origin/master |
No difference is reported as our local repository does not know what have changed in our remote repository. You can update your local repository to make those changes visible to it in two ways – git fetch or git pull. The difference between the two is git fetch only gathers the updates (what changed) in your remote repo but does not include them in your local repository whereas git pull gets those changes and also update (merge) your local repository with those changes.
1 2 3 4 5 6 7 8 9 |
## Update the local repo with git fetch git fetch ## See what’s updated git diff master origin/master ## Now you can find the difference ## See what’s changed cat README.md |
But files are not yet updated. If we had done a pull instead of fetch, README.md file would also have been updated. We are going to do exactly that in next step
Update your local repository using git pull
1 2 3 4 5 |
# Finally pull the changes git pull # See what’s changed cat README.md |
Observe the file README.md also has been updated
Step 13: Creating a Pull request in GitHub.
Navigate to your remote repository and click “Pull requests”
You can directly create a pull request to merge branch1 with master by clicking “Compare & pull request” or click on “New pull request”
Select the source and target branch and click “Create pull request”
Add a comment and click “Create pull request”
Accept the pull request by clicking on “Merge pull request”
Branch1 successfully merged with master, if you want you can delete the branch1.
Hope you have enjoyed this article. To know more about GitHub, please refer below official documentation