Coding Diary

Github, Git and Repositories

Jasmine Liu
4 min readJul 30, 2017

Today we will learn about Git and Github. The topics we’ll cover are the following:

  • What is Github?
  • What is Git?
  • What is a Git repository?
  • Creating Git repo
  • Updating Git repo

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

What is Github?

Github is a software development platform for programmers to store their code. Some put it as the “cloud” for code. It’s a great place to keep a backup of your coding projects.

What is Git?

Git is a version control system that makes a copy of your local project to Github and keep track of changes you’ve made.

What is a Git repository?

A Git repository, or repo, is a data structure used by Git to store the information about your projects and files. A repo is made on Github and updated through Git.

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

GitHub and Git are extremely useful, not only for sharing your code with others, but also as a backup storage for all your precious codes. When you “push up” your code, all of your push history is recorded and everyone can see just how committed you are to coding. Therefore, it is an impressive place to start building your personal brand.

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Creating a Git repository

Here is a step by step process to creating your first repository for an existing project folder. Beware! If you’re using an api key, you need to take extra steps before pushing your code! Otherwise your key is open for all to see and use. This can be a costly mistake. If you have an api key, go here to take the appropriate steps.

  1. Create an account at Github.
  2. On the top right corner of Github, click the + and select “New Repository”. You’ll be taken to the Create a new repository page.
  3. Now create a new repository. Recall the exact name of the project folder on your local drive that you want to make a repo of. Type that name into the Repository name field. For example, if your folder is called “color-app”, your repo name will be just that. Click the green “Create repository” button. Note: do not make a repo of projects with other projects embedded in it! This only confuses you and everyone else looking at your code. One project, one repo.
  4. You are now taken to a page where you can setup the repo depending on what you want to achieve. You can create a new repo on the command line or even import code from a different existing repo, but since we already have a folder we want to use, we will simply push an existing repo from the command line, aka push up your code. Keep this page open and open your terminal.
  5. In your terminal, cd into the folder you want to push and input command git init . This command lets git start tracking the folder you’re in. This should only be done once per folder.
  6. Now in your project file, make some edits. Save it. Then back in the terminal, input command git add --all . This will add all changes you’ve made in the folder. Alternatively, you can git add .filename. This allows you to choose specific files to commit to your repository. Be sure you are within the right project folder when running git commands.
  7. Next input command git commit -m "A descriptive commit statement". Write a good commit statement that describe the changes you’ve made to your folder. This is key to keeping your tracking records neat and easy figure out. If you’re using git in a team, your peers will thank you later for writing clear, descriptive commit statements that are easy to understand.
  8. Now go back to your repository page on Github and copy the line git remote add origin https://github.com/username/foldername.git. Use your Github username and the project foldername, aka repo name. Paste this in terminal command line and hit enter.
  9. Then on the repo page under the line mentioned above, copy the line git push -u origin master. Paste this in terminal command and hit enter.
  10. Now run git status to check if your everything in your repo is up to date. Alternatively, you can run git diff to see changes that are different between your last updated repo and your local repo.
  11. Go back to Github to your new repository page and refresh. You should now see all the files and folders within your project online!

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Updating a Git repository

Now if you’re done with your project, and you’ve pushed up the latest code, then this is the end of the tutorial for you. But if you continue to make changes to files in your git repo, be sure to always push up your code by repeating the following steps:

  1. Make some edits to your project folder and save.
  2. In terminal, input git add — all
  3. In terminal, input git commit -m “descriptive statement about changes”
  4. In terminal, input git push origin master
  5. In terminal, input git status (check if your repo is up to date)

And you’re finished! It takes a little while to learn the ropes, but once you got it down, you will learn to appreciate the Github platform and what it can do for you. :)

--

--