Hi, in today's blog, I will share with you how to
Create a Repository on GitHub
Pull the Repository from GitHub to the local machine
Push changes in the Repository on GitHub
Prerequisite
First, you need to have installed Git in your local system.
Secondly, an account on GitHub.
If you do not have any of these, don't worry. Just follow the steps.
Install Git
Open your Linux terminal.
Update the packages:
sudo apt-get update
Install the Git
sudo apt-get install git -y
And you are done with installing Git in your system.
Verify Git
Let's verify whether Git is installed or not by checking the version of Git:
git --version
Now you have Git installed. Let's go the GitHub and create an account.
Create GitHub Account
To create an account on GitHub visit: https://github.com/ This is GitHub's official website.
Here, Click on sign up and enter:
Email
Password
Name
etc.
After that, it may ask you to verify your email.
That's it. Your account is ready.
Create a Repository on GitHub
To create a repository, go to https://github.com/new
You will see a form like the above image. Fill up the form.
Enter the repository name, I have chosen
Devops-Day08-Challenge
as my new repository name.You can describe the repository in the Description. I have written:
This is my Day 8 challenge of #90DaysOfDevops
Click on Create repository button.
Your repository has been made and is ready to use.
Setup Git
Now, let's go to our machine and create a version control and add with remote one.
Username and Email
To use git you have to give your email and username to git for tracking records.
Open the command line.
Set your username:
git config --global user.name "FIRST_NAME LAST_NAME"
Set your email address:
git config --global user.email "MY_NAME@example.com"
Git init, add, commit.
Open terminal.
Create a folder name
Devops-Day08-Challenge
(similar to the repo)Make this folder a version control with git.
git init
Add some files to the folder.
I will add a readme file.
vim README.md
Write some description in this file:
Stage this file to Git version control:
git add README.md
Commit this change to git with a message.
git commit -m "initial commit"
Add Repository in Git
Use the git remote add command to add the repo to git.
git remote add origin https://github.com/neelsoni26/Devops-Day08-Challenge.git
Verify with
-v
:git remote -v
Personal Access token
To push and pull the repository you need to have Personal access token for the password.
To create your Personal access token:
Go to GitHub Settings > Developer settings> Personal access tokens >tokens (classic)
- Or simply visit: https://github.com/settings/tokens
Click on Generate New Tocken
- Generate new token (classic)
Give a name
Set Expire
Select scopes (Permission of)
Click Generate token.
Copy the token and save it in a safe place.
Push the Change
To push the changes from local Git to GitHub git push
command is used.
git push origin master
Enter username and Personal access token.
Done! Your changes are now on GitHub.
Pull the Change
Now let's say you have made some changes on the GitHub website in the repository, How you will get that in your local repository?
Simple, Using git pull
command.
Suppose, I update the README.md file from the website.
I have updated it to give a link in the text.
And commit to the change.
To get this change in my local I will run the command:
git fetch -all
git pull origin master
Now let's check the change.
Done. You have Created, Pushed and Pulled the repository from GitHub.
If you like the post do like, have any queries? do comment and share the blog ๐