Git and GitHub for beginners

Sadat Jubayer

Sadat Jubayer

October 09, 2022

3 min read

What is Git?

Git is a version controlling system. It is just like a tracker. But what does it track? It tracks your file changes. The file can be any file type (.txt file, .js file, .php file, video file etc..). It also tracks when the file changed, who changed it, which line of it got changed, all of these.

And an outstanding feature of git is it tracks the previous version of your file!

What is GitHub?

Git tracks your local changes, local versions. But when it comes to working as a team on different computers, you need to share your code/code-versions with your team members to work together on a centralized codebase. Here comes GitHub; it takes your local files on the cloud. You work on your local machine, track versions, then upload them on GitHub; your team members do the same. Thus a project's code got centralized.

GitHub is not only the cloud service provider, there are many of them, but it is the most popular one.

Behind the scene

To work with Git, you don't even need an internet connection. You can track your files on your local machine and get all the benefits of Git. But to sync your files with other teammates or to keep your files (with versions) on the internet safely, you can use services like GitHub. Let's have a look at the diagram and know the buzzwords -

Git and GitHub Workflow
  • Local: Your local computer
  • Remote: GitHub, where you'll upload your files
  • Working Directory: The project's folder where you're working on your computer
  • git add: Takes your files from the working directory to the staging area.
  • Staging area: After adding, editing, or remove files from the working directory, you need to stage the files, which means it's ready to be committed.
  • Commit: It's like a snapshot. When you commit, the files are on the stagging area becomes a snapshot from that point in time. You can track your file history with it.
  • Repository: Just like a folder
  • Remote Repository: Folder on GitHub
  • git push: To upload your files from your computer to GitHub
  • git pull: To download your files from GitHub to your computer.

Git Workflow

A typical git workflow is like this:

  • Making changes to your files (adding, editing, removing files)
  • Staging changes using git add
  • Committing changes using git commit
  • Pushing changes to cloud using git push

Git Branches

Branches are individual projects within a single git repository.

Different branches within a repository can have completely different files and folders and commits or same as the other branch with a few changes. You can easily switch to different branches and work on individual projects within a single repository.

.gitignore

.gitignore is a file that contains some file and folder names. Git will ignore these files and folders to keep tracking and pushing to the remote.

To know the basic commands of Git & GitHub you can follow this article.