Version Control

Ian Value
4 min readSep 19, 2020

The key to figuring it all out in the terminal.

Photo by Matt Artz

The Github service has been around since 2008. It is a safe and easy way to share and update your projects with others. To get started, you should definitely download a Git cheat sheet. This is just one of many. You can use this one or find one that suits your needs. If you have not worked in terminal before, a bash cheat sheet is also helpful.

So you now have all the tools necessary to work with git. Now you just have to learn how to use them (I will not cover install because it’s already well documented. There is a link on the cheat sheet.).

1.) Adding a project

To start, go to Github and either sign in or sign up. In the top right hand corner there is a + button. Press it and select new repository. Add a repository name and description. The other options are up to you. Click next. On the next page you will see helpful instructions on how to add your project to Github. Let’s now go to the terminal. On a Mac you can press command and then space. This will enable spotlight. Type in terminal, hit enter.

Navigate to your desired project. Bash commands that come in handy here are:

pwd : Present working directory

ls : List contents of directory

cd : Change directory

cd .. : Change directory one level up.

Once in your project directory:

git init: Tracks the changes to a project.

git status: Gives you the ability to see if a file is being tracked or not.

git add [someFile.txt]: Adds a specific file. You can use add -A to add all files, or add . to add any new untracked files

If you type git status again you will see the new files that are tracked but not yet committed. Next is to commit the file or files to the project. You can use:

git commit -m “use a reference note here”: This will add the file to the project. You will typically see how many files have changed as well as insertions.

If you now type in git status it should say “nothing to commit, working tree clean”.

At this point you can push your project to Github. Go back to the Github setup page. Look for the clipboard next to the repository name and press it. This copies the link.

In your terminal now type:

git remote add origin then paste in the copied link and hit enter.

Next lets finally add our project. Now type:

git push -u origin master

You will be asked for your username and password. If you get an error or you don’t have an ssh key, in terminal type:

ssh-keygen

It will ask you for a password. Add and confirm password. Navigate back to Github. Go to settings and find in the tab that says SSH Keys and press it. Add a descriptive name to the key. Navigate back to terminal. Now type:

cat .ssh/id_rsa.pub

After pressing enter, copy and paste contents into the key back in Github. Now you can push and pull with your ssh key instead of using your username and password.

2.) Using branches

Branching your project makes it possible to work in a safe environment without breaking your projects code. It is so awesome. So how do we use branches. You guessed it:

git branch

Super easy to remember 😂. This creates a master branch by default. This is for your final product. If you would like to work on a special feature or make changes to your project, you can make a special branch to handle that:

git checkout -b nameItSomething

This makes a copy of the project your working on. If you want to look into the created branched simply type:

git checkout branchName

This lets you checkout and work on that version or branch of your code. Typically you can use the previous method of adding this branch to your project.

git status

git add -A

git commit -m “name commit”

If everything looks good you can add the updated project to your master branch by typing:

git merge nameOfBranch

This merges your updated branch into the master.

3.) Merge Conflicts

We can expect that if we are working on a project with other developers that we may inevitably run into a merge conflict at some point. How can we minimize the chances of that happening and also what can we do if it does happen. Below is a great site that has in detail how to not only handle merge conflicts, but identify and work through them. I was going to write my own thoughts on this, but its covered so well here!

Well, thats the nuts and bolts of Github. Like any tool it can work incredibly well and improve your life if you know how to properly use it. The key, I think at this point, is to take your time with it. Be slow and methodical.

--

--