‘Git -er “Done.”’

Corey Lynch
8 min readAug 16, 2020

Synopsis:

In this article, I intend to create a Github primer for programmers to be able to quickly skip through. This article assumes that you have a Github account already.

The topics included below are:

  • A glossary of terms to help people decipher any terminal messages they are getting or commands they may be trying.
  • A procedure for creating and tracking a new project on Github for yourself.
  • A procedure for creating, tracking, and collaborating on a project using Github with others.
  • A procedure for making a contribution to something you found on Github.
  • Some basic troubleshooting steps.

Glossary:

  • Add — elect to be added to the index on the next commit.
  • Commit — Record the current changes and a log message describing the change to the contents of the index.
  • Head — A symbolic reference (reference to another reference) pointing to the branch you are currently on.
  • Index — is used as a staging area between your working directory and your repository. The index can be used to build a set of changes that can be committed together.
  • Repository — is the .git/ folder inside a project. It tracks the changes and creates a history of the files in your project.
  • Status — Show the working tree status.
  • Tree — Hierarchy between files in your git repository.
  • Remote — “Manage the set of repositories (“remotes”) whose branches you track.”
  • Push — “Update remote references along with associated objects.”
  • Fork — Copies the repository to your account.
  • Clone — Copies the repository to your local machine
  • Branch — represents a separate path of development and can be merged to the main path of development, discarded or disregarded. The git-branch command lets you list, create, or delete branches.
  • Checkout — “Switch branches or restoring working tree files.”
  • Help — Displays helpful information about git. Can also be used as an option ( — help) on any command to display helpful information about that git command.
  • Merge — lets you take separate paths of development and put them together to form a single line of development. Often this will cause conflict between what currently exists and what you are trying to make exist, upon which you would go through and tell which of four options you prefer on each conflict if there are any conflicts.
  • Originis shorthand for the remote repository a project was originally cloned from.

How to Create and Track a New Project Using Github For Yourself

  1. Create a new repository

2. Name your repository

3. On that same page, click the ‘Create Repository’ button after you’ve named it.

4. You’ve done it! Now we need to add your new repository to your machine. To do this we will use the following commands:

Step 1. Creates a markdown file called “README”. This file will say “#Testrepo”.

Step 2. Creates ‘.git’ directory. This is where all the git related work is done.

Step 3. Elevates a file called ‘README.md’.

Step 4. Commits all elevated files to the index. This commit will be called “first commit”.

Step 5. Adds the repository ‘Testrepo.git’ to the ‘.git’ directory as the original repository for this directory.

Step 6. Adds the commits on your master branch (default branch) to the repository URL for origin.

5. And now our repo reflects our changes!

Working with others on an existing project/ Contributing to a project

The beauty of Github is that anyone can collaborate and contribute to projects just as if they were on a team and so I can talk about working on a project with a partner, or a team in the same context as I can for an individual wanting to contribute to a project they found interesting while they were exploring Github.

There are two sides or perspectives to these concepts though. There is the perspective of the person making the change and the perspective of the person receiving the change. Since this is just a primer I will just review how to make and submit a change and leave the details of receiving changes and merging those changes into the master branch for another time.

  1. For this walkthrough, I am using this repo and I recommend you do also if it’s your first time forking and/or pulling.
  2. After you have navigated to the page you want to work on you’ll need to click the “fork” button.

‘Forking’ a repository makes a copy of that repository and adds that repository to your Github account.

3. When Github is done making a copy of the repository for you, it will bring you to your copy of that repo. From here we need to ‘clone’ the repo onto your computer so you can make changes to it.

Step 1. Click the ‘Code’ button to reveal the menu with this directories URL.

Step 2. Click the clipboard icon to copy the URL.

Step 3. type the command ‘git clone’ and then paste the URL you copied on 2 and hit enter

4. A copy of that repo is now saved to your local machine and you are free to make any changes you please.

Step 1. The first thing you will want to do is to make sure you are in the project directory.

Step 2. Second, open the project.

Step 3. Lastly, you should make a new branch for your changes. You should name your branch “add-<first-name>-<last-name>” in this case since we’ll be pushing the branch i.e, git checkout -b “add-corey-lynch”

5. After you’ve created your branch it’s time to make our changes. Open the file Contributors.md and add your name somewhere in the middle of the list.

Step 1. I added my Github as well. If your following along, feel free to join me on line 3414.

6. Now that we made a change to the file we should elevate the change, stage our changes to the index with commit, and then push the updated index to our Github repo.

Step 1. Elevates the changes made in the file ‘Contributor.md’.

Step 2. Stages the elevated changes.

Step 3. Sends staged changes to the repository.

7. Now we should review the changes we just sent to our repository. We can do this by clicking the ‘Compare & pull request’ button.

8. Leave a comment for the maintainer of the repo we are requesting to change, review the changes made on the bottom of the page and if everything looks satisfactory to you, click the button ‘Create pull request’.

Step 1. Review your changes

Step 2. Leave a comment

Step 3. Then, submit the pull request. You’ve just finished your first pull request. Way to make a contribution to the open-source community!

There are many errors you can run into while working with Git. Luckily for us, Git is extremely well documented, and with some best practices, you’ll be back up on your feet in no time.

I work with Github out of necessity and it was a long time before I knew the meaning behind any of the commands I was typing into my terminal. In that time there were a few issues I consistently ran into so I included the following in case you run into it while following this guide. Also, be sure to check out the resources at the end for more information.

  1. ‘.git’ is the index that holds all of your committed changes. This is the directory that interacts with both Github and your computer. This folder also keeps a history of changes.
  2. ‘Fatal: remote origin already exists’ means that the directory you are working in is already being tracked by Github. Refer to ‘.git’.
  • You can either find the specific ‘.git’ file responsible for tracking the directory you are trying to add to a repository.
  • Or you can find and delete the specific ‘.git’ file tracking your directory.
  • Or lastly, the easiest thing to do is to just go to your home directory and delete all your ‘.git’ files. Not recommended if you have staged changes to make.
$ cd ~$ rm -rf .git
  1. If you stage a file but then decide you don’t want to push it, you can use ‘git reset’.
  2. If ‘git reset’ doesn’t get it done for you, try harder, ‘git reset — hard’
$ git reset$ git reset — hard

That’s all I got you all today. If you spot any errors or have a better way of doing things, please leave a comment or reach out. I’m still learning Git and would love to know more about it.

In the meantime, if you are looking for more information on Git please check out these great resources that I used in making this article.

Resources:

Git’s Website

https://git-scm.com/

Git Community Book

http://shafiul.github.io/gitbook/index.html

Git Kraken UI

https://blog.axosoft.com/

Github Developer Portal

https://developer.github.com/

‘Git Fork Vs Git Clone’ by Hariprasath Thanarajah

https://medium.com/@tharis63/git-fork-vs-git-clone-8aad0c0e38c0#:~:text=Git%20Fork%20means%20you%20just,to%20your%20own%20GitHub%20profile.&text=Then%20make%20your%20changes%20and,it%20to%20the%20main%20repository

Tower Git Client

https://www.git-tower.com/mac?utm_source=learn-website&utm_medium=navigation

‘Fatal: remote origin already exists’ & when it’s appropriate to use Git Remove

  1. https://stackoverflow.com/questions/1221840/remote-origin-already-exists-on-git-push-to-a-new-repository
  2. https://www.datree.io/resources/git-error-fatal-remote-origin-already-exists
  3. https://git-scm.com/docs/git-rm/2.13.7

For being amazing by providing a platform for anyone to get their first pull on and become an official open-source contributor

https://github.com/firstcontributions/first-contributions

--

--

Corey Lynch

Frontend Software Developer and Security Technician with experience in Ruby, Rails, JavaScript, and React. Flatiron Software Engineering Alumni.