One of the earliest things I learned while coding was centered around a system called Git. It became clear very quickly that Git skills are very important, both for coding individually as well as with a team. So, for this piece, I wanted to go over some of the more common git commands.

What is Git?

Git is a version-control system used to track changes on a set of files, and is very popular among programmers. With teams working on the same set of code, it can get confusing to make any edits to a code base without a system such as git. Git operates using commands entered into the terminal, with each command running a specific function.

git init

Git init is used typically at the start of any new project, as this command creates a new git repository. This can be used either as a blank repository, or to convert existing code that has not been set up with git.

git clone

One of the commands I used quite frequently during my time with the Flatiron School, git clone will create a local copy of a repository and save it to your local system. For example, as we used it during our coding bootcamp, in labs we needed to save onto our computers, we used git clone to save a local copy in order to work through.

git branch

This is one of the most important commands in team-based coding. Git, as a system, uses different branches within its code base to make sure coders aren’t stepping on each other’s work as they work. If two coders are working in the same piece of code, they will often create separate branches to work off of, starting from the same copy of the code. This ensures that any edited code by one doesn’t affect code in the other. Quick note, this command will only create a branch locally, as you will need to “push” (we’ll visit later) the branch to the remote repo in order for others to see it.

git checkout

Once a new branch is created, we must navigate to it before we can use it, that’s where this command comes in. In order to move from one branch to another, we enter “git checkout” and the name of the branch.

git add

In order to make changes to any repo within git, we must first add the files that will be changed, which is where git add comes in. Depending on the need, you can add a single file or a full add of the entire branch you are working on. Quick note: Changes are not saved until we commit them, see next.

git commit

Once files are added to our changes that are made, we must commit those to the repo. Using git commit, which may be the most used command within git, makes these changes LOCALLY. It should also be noted that the git commit uses a message feature on entry, so a typical commit command may look like this: “git commit -m “navbar implemented”. This allows easy retrieval in case a commit needs to be undone for some reason.

git push

Now, as I mentioned in both of the above commands, everything we’ve done from git add to git commit has only changed the files locally, or on your own computer. In order to push them to the remote repo, we use the command git push. This makes all the changes active anywhere the repo is accessed from.

git pull

Much as the opposite as git push, this command will “pull” all changes that have been made from other places in the repo to your local system. This is necessary if you have not been coding, but others on your team have done so, to make sure you all are working off the same code.

Flatiron School DC. Learning to code one day at a time.