Git Educated-What is Git and some of its basic commands?

Maybe you have just started your coding journey and seen the famous Octocat and heard about Github, but don’t really know what it is yet. In this article, I’ll give a brief overview on what Git and Github is, some basic terminology, and git commands for newbies. Let’s get into it!

What is Git?

Git is a Version Control System (VCS). It is a way to manage project files and track and store content. On an individual basis, VCS are useful because they keep track of every modification to the code. If a mistake is made, developers can revert back to an old version of their code via a VCS. This is also super useful if you want to experiment with things, but fail miserably and want your old code back! In a team setting, VCS are helpful because it allows for easier collaboration with other developers. With Git and other VCS, developers can code in parallel to each other on the same project, without disturbing other’s files.

What is Github?

Github is a web-service that offers hosting for software files and version control using Git. In other words, its a place for developers to store and manage their code in addition to tracking and controlling changes to their code. It is also kind of like a form of social media for developers. You can see other developer’s profiles and the public projects and code they have been working on. Some alternatives to Github include BitBucket and GitLab.

All hail the mascot of Github, the Octocat!

Basic Git Terminology

Repository: Also called a repo, a Git repository is a folder that holds the source code

Branch: A branch is a duplicate of the source code. When working on a branch, this allows the developer to safely make changes to the code without affecting the main (or master) branch of the code. If the changes are satisfactory, they can merge the code into the main branch.

Main: The main (or master) branch of the code is the active default development branch.

Commit: A commit is changes you made to a file or a set of files. You can add a message to each commit which helps keep track of what you changed.

Pull Request: A pull request is a request made to other developers working on the project to approve and include your code into the branch you are working on. If there are merge conflicts (changes from competing commits that conflict with each other), these must be resolved before the pull request can be merged

Fork: When you fork someone else’s repository, it creates a copy of the repo into your account.

Clone: When you clone someone else’s repo, you create a copy that lives on your computer.

Basic Git Commands

git initCreates a new repo from an existing directory on your computer

git checkout -b "Name of branch" Creates and switches you to a new branch

git checkout main Switches you to the main branch

git add . Adds all the files and their updates to your next commit

git commit -m "Descriptive message of your commit" Commits your new staged content

git push origin head Pushes your commit up to the remote repository branch. head pushes up your commit to whatever branch you are currently working on, but you can manually type in the name of the branch like git push origin <branchname>

git pull origin main Pulls down the remote repository (main) code so the code on your computer is in sync with that

Hope you learned something new! I’ll leave you with a great cheatsheet for other git commands. Thanks for reading!