In this tutorial, we are learning how to add your local machine project to the GitHub website. First, before starting the tutorial we need to understand what is git and GitHub. Git and GitHub both are different.
Git is a version control system or software which is handling small to very large projects in an easy and efficient way. also, it’s free to use and easy to learn. Go to https://git-scm.com/ and install it. Git is work on the local machine for data sending and pulling requests, we will learn more about it later.
GitHub is a code hosting platform or website, which is managing the project as a repository. GitHub provides multiple user support for working, also supports multiple branches of a single project. To store the project we are using the git bash command line terminal.
Now it’s time to create a example project for understanding how things working step by step.
Step 1: Install Git on your machine.
Go to official website https://git-scm.com/ of git and download and install it on your machine.
Step 2: Create GitHub account.
Go to the GitHub website https://github.com/ and register your account. After that create new repository as “demo project” .
After clicking new repository an form appear then fill project name and submit it.
After successful create an repository it look like this.
Step 3: Now create a folder on you local machine
Now time open git bash terminal and enter path of your project and run the below command.
cd C:\xampp\htdocs\git\demo project // folder path for implement git
echo "# demo-project" >> README.md // this command are create reade me file for your project
git init // this is inisilise git feature in your project.
git status // this command are show current status
Now we create a index.html file on over folder and check the status of git.
C:\xampp\htdocs\git\demo project>git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) README.md index.html nothing added to commit but untracked files present (use "git add" to track)
Now we need to add files for git used, run the below command.
git add -A // or git add README.md git add index.html // these command are added into the git envirment.
let’s check the current status.
Now we need to commit all files using below command.
git commit -m "first commit" // this command added an comment into the log
git branch -M main // this command use for switcing the main branch.
Step 4: Connect Remote GitHub
Now time we need to connect remote to our local machine. for this use the below command.
git remote add origin https://github.com/<username>/demo-project.git // this command are used for connecting to remote.
Now we need to push over data to the server for that use the below command. After that command, it will ask you for credentials detail of the GitHub user account.
git push -u origin main // this command will push your data to the remote
Now go and check your repository on GitHub, It’s look like below.
That it, you have created your project into the github repository. If you wanna learn more about git and github you can check their official documentation. Learning is a key of success. let check our more blog.