Getting Git

A Guided Intro for GitHub/Git

Hunter Posey
7 min readJan 14, 2021

Initial Fear

When I began coding, I was blind to the world of git and GitHub. It was just another piece of this massive puzzle we find ourselves in. With everything was trying to learn, GitHub didn’t fit in. Everything I would search on the matter would throw me into a tailspin of anxiety driven rabbit holes. So, I completely threw it out for time being. Everything seemed so hard when it came to getting it set up and running. Things got even worse AFTER it was set up to the point where you could actually use it. I couldn’t understand what my terminal was wanting. I couldn’t understand what GitHub was wanting. I was LOST!

When I began my Bootcamp pre-work for the flatiron school, there was a module with steps to setup GitHub and git on my end in a “loose” way. One thing led to another and I ended up with 3–4 different SSH keys scattered onto my computer(deleting them could have its on blog post, or 5, literally). I sat back, took a breath, and somehow someway, it worked. I didn’t touch it or even use it until Bootcamp day 1. After that, git and GitHub, became a second nature. For the most part…

Through tried and true processes and a little organization, I present a guide to help any new comer through the hardships of using git/GitHub.

Recently, I have had the pleasure to really get to know the world of git. I have developed a personal routine when coding and pushing things up to GitHub that have really helped me through. Whether it be a Personal Project or Project with multiple contributors, I hope this article can be a source for your learning!

please have your GitHub setup with your local machine before proceeding.

How-To Git

When learning git, you will become quite familiar with your terminal if you haven’t already. If not, I highly recommend going over some terminal command basics.

Alright, ready?

First things first, I will try to explain from two view points. The view of forking a repository and going through the steps, and the view of creating project/repository from your local machine. Both views will tie in with adding multiple contributors and creating branches.

This is simply a process that is very efficient to me. In no way is this THE absolute way to do it. If there are suggestions, please don’t hesitate to let me know. Knowledge is {:key}.

VIEW: Forking

When forking from a repository from GitHub, the process is honestly fairly simple. Lets start with your terminal. On your computer, open your your terminal. Make sure that you are in your home directory. We are going to create a folder for the forked repository in the directory of your choice, such as the Desktop or Documents directory. Lets do it from our terminal:

cd <directory>

mkdir <folder-name>

cd <folder-name>

From here, we can begin commanding git from our terminal. If haven’t already, find a repository to be cloned. When you are ready, click clone, assuming your SSH key is set up properly, you can click the clipboard icon next to the URL on the SSH tab. From your terminal(where we left off):

git clone <paste-URL>

After the clone is processed and everything checks out, your repository is ready to be opened. The process gets even easier to see your new clone as you can use your terminal to open the IDE of your choice! I’m going to include the commands for the 3 biggest IDE’s that I know of, no doubt there are more.(where we left off):

code . (VSCode)

atom . (Atom)

sublime . (Sublime Text 3)

The ‘.’ opens ALL contents of the folder

Pretty simple, right?!

VIEW: Project/Repository from Local Machine/Initialize

This part can be a bit tricky. But, no fear! We will work through this together. First, make sure that you have a file ready to open and work with. To make things a little more streamlined, create a new folder in your directory of choice and drop your file/project into that new folder.

Before we get into our terminal, navigate to your GitHub in the browser. Click the drop-down arrow next to your profile icon on the top right and navigate to “Your Repositories”. Click the green “New” button. Enter a name for the repo and leave the rest as is for now.

On your terminal, from the main/home directory

cd <directory-with-file>

cd <filename>

If you have previously ran ‘git init’ on subdirectory of your file on your local machine, you may not need to run it again for a file within that subdirectory.

git init

After initializing(depending), make a change inside the file/project and then follow along in the terminal.

git add .

git status(optional: to check if files are staged as directed)

git commit -m “your message”

git remote add origin “https://github.com/<github-username>/<your-project-name>

git push -u origin master

You will be asked for your GitHub username and password. After authenticating.

Congratulations! You just set up a remote repo for your project on GitHub. Awesome stuff, really. Everything you push up will be saved through the power of git so really, you will never have to worry about losing anything!

Adding Contributors

Adding contributors introduces us the amazing things GitHub and git give us. You are able to add multiple contributors to your project as needed. Those contributors are given access to clone your repo, change code, make branches, and push things back up to the master branch. This comes in handy when working in groups obviously, but it is really a staple of what most companies use and how they use it. So, from that, lets get started.

Navigate to GitHub and select your repository that you want to work with.

Locate the “Settings” tab select it.

On the left side, locate “Manage Access”.

Click the green “Invite a collaborator” button.

Insert the other contributors name/username/email.

That’s it! You have successfully added a contributor to your project. All they have to do now is clone your repository and create a branch! Everything is coming together!

…and speaking of branches…Lets go through the steps to create and delete branches.

Creating/Deleting a branch

GitHub Mascot

Branches are SUPER useful when using git. Branch act as, well, branches! Think of a tree branch. What is the branch connected to? The TREE! Or in our case, the Master! Since they are connected, we have the ability to make changes on a branch off of the master branch and test those changes before ever merging it with the master! Pretty awesome stuff. Lets get started.

Make sure your project is open and ready to go. Make sure that your terminal is cd’d into your project folder. Check that everything is ready by typing “git branch” in your terminal. If “*master” in green shows up, you can move forward. In your terminal:

git branch <name-of-your-branch>

git branch (to check that the new branch was create)

git checkout <your-branch-name>

From here, you are on your new branch. Make some changes in your project on the new branch and make a commit to the branch by doing:

git add .

git status(optional)

git commit -m “comments”

git push <your-branch-name>

You can switch and check branches as often as you’d like with:

git branch

Deleting the branch is as simple as:

git branch -d <branch-name>(Soft Delete, Recommended)

or

git branch -D <branch-name>(Hard Delete)

Branches will make your coding life SOO much easier, especially with multiple contributors!

Pushing/Merging

Finally, we arrive at the end of our git journey. Pushing and merging are KEY to using git and GitHub properly. Pushing is the way to push all that glorious code you have written up to your GitHub repo to be saved and viewed. Merging is a way for you to merge all of your changes or creations on a different branch and add them to the master branch. Of course, you can do this with any branch!

From where left off in our terminal:

git checkout master

Notice that when in master, the changes you made on the other branch are not displayed. To fix that:

git merge <your-branch-name>

Voila! Your changes should appear on the master. If everything is to satisfaction, your master is ready to be pushed to your repo!

git add .

git status(optional)

git commit -m “comment”

git push origin master

That’s it! We did it! Hopefully this article was able to get you through any tough time with git you may be experiencing! There are SO many things to learn with git. There are many different rabbit holes to explore. For now, at a low/intermediate level, this will suffice. Don’t think to hard into git though! It is very powerful when you get the hang of it. The fear will eventually subside and you will be using get like a developer pro!

I welcome all suggestions, comments and improvements!

Good luck, and happy “gitting”!

--

--

Hunter Posey
0 Followers

Software Engineering Student @ Flatiron School Music and Cinema Nerd Phish enthusiast