Git basics [Beginner Mode]

Git is an SCM tool and combined with GitHub it can do more than just tracking the version. In this article, I am gonna show you all the git commands that I used in my project. So let’s get into it…

A repository is a folder in a GitHub server that will contain your project files. And this repository has more functionality than your typical folder in your system.

A commit is a snapshot of your work at the moment.

A branch(except the main branch) is a sandbox for testing new code on the existing codebase. Any changes to your project in a separate branch will not affect your main branch.

Firstly to create a new repository for your project,

Open your project directory/ create a new project directory and open terminal and type:

  1. git init to initiate a new repo.
  2. git branch -m master main to move the old master branch convention to main (optional)
  3. git remote add origin <your remote URL> to connect local and remote repository
  4. git remote -v to verify the new remote URL.

That’s it, you’ve just created a new repository 🥳. No lets start the work,

Create README.md and .gitignore files.

README.md:

It’s the file that showcases your project in GitHub. This file will automatically be shown in your GitHub repo once you uploaded the files and this is not a normal text file but a special file called “md” (markdown), this is a text file but with extended functions.

.gitignore:

Git will consult with this file every time you make a commit to checking which files should be tracked. Simply type the names of the file that you don’t want to be tracked like your IDE’s configurations and private keys and other secret files in a project.

So when you add files for commit you don’t have to worry about accidentally uploading secrets to the remote repository.

Now we have created these files so now we can commit these before we start the project. So,

  1. git add <filename> <another filename> to add the files to track. You can also use “git add .” to add all the new files.
  2. git commit -m <your commit message> to create a snapshot of your project. Add a nice message for future to check what has changed over time on each commits.

Now you have created a snapshot of your project but the span shot is present in the local machine, we want to take it to the remote repository (GitHub). To do that:

git push origin main

You can replace the “main” with any branch name but you will see how to do that in the next article.

That’s it, you have successfully created a repository and uploaded your code to the remote repository. Now what… Well, there is still a lot more to learn to make your coding life easier with git but we will learn about that in the next article. 👋

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
hiruthicSha

hiruthicSha

Python, JS developer | Flutter | Fitness and self development