GitHub Basics 101 🍻
If you’ve ever thought about putting your code online or you want to learn Version Control System (VCS) for your pushing your projects GitHub is an ideal place to get started.
In this blog you’ll get to know about the GitHub basics —
- Setup
- Creating a Repository
- Connecting the repo to your system
- Adding your code to Git
- Committing changes
- Pushing code to GitHub
Setup
To setup a GitHub account visit — https://github.com/signup. If you already have an account, simply sign in. Once you have your account ready proceed to the next steps.
Creating a repository
A repository (or repo) is like a folder/directory on your system, it’s a folder present in your account which contains the code and files you put there.
To create a repo —
- Click on the “+” icon in the upper right corner of the GitHub homepage.
- Select “New repository”.
- Fill in the repository name, description, and choose whether it should be public or private.
- Click “Create repository”.
Now that we have created a repo the next step is to connect it to your system and push your project to the repo.
Connecting the repo locally
To connect your repository locally you need to open your terminal / command prompt
and navigate to the directory where you want to clone your repo.
git clone https://github.com/yourusername/your-repo-name.git
Replace yourusername
with your actual username and your-repo-name
with the name of your repository.
Now if you use dir
command, you’ll see a folder having the same name as your repo, use cd your-repo-name
to direct yourself there.
Adding your code to the repo
If you are starting a new project, then code it in that folder itself and if you have already made a project then move its files to the repo.
Then use the git status
command to see the status of your files.
To add all the changes which you have made to your repo use the git add .
command. You can again use git status
to see what’s changed.
Committing Changes
When you are ready to push your code to the GitHub repo use the following command to commit it first.
git commit -m "add my project version 1.1"
The -m
option provides your commit with a message which provides the information about what you did in that commit.
If you want to make more changes to the project, then make those changes and use git add
command add then use the git commit
command to commit those changes with a relevant message.
Pushing your code to the GitHub
Finally, to push your local project to the destined GitHub repo use the following command —
git push origin main
This will upload all of your commits to the GitHub repo.
You can check your project at — https://github.com/your-user-name/your-repo-name/
and verfiy the changes.
NOTE: Only the files which you have committed will be shown in the repository and if you want to skip some files like
logs
orirrelevant files
then you can use.gitignore
file.
Commands covered —
git clone https://github.com/yourusername/your-repo-name.git
git add .
git add index.html
git commit -m "add index.html file"
git push origin main
I hope this blog helped you to learn the essential commands to getting started with GitHub. There is more to GitHub like — branches, merging, conflicts, pulling etc.
but these are the essentials which everyone should know.
If you have any problems with it feel free to ask in the comments : )