Starting with Git

Making and Continuing Projects

Let’s learn about git. It’s a very useful tool that is really in-depth and has a bunch of awesome features, like how to bug hunt with git. If you understand what is going on in that post, this post may be too basic for you.

We assume:

  • You can use very basic terminal commands (mkdir, cd)
  • You have at least a basic idea that git is some kind of work-saving system, and you want to use it in projects but don’t even know where to start

We are going to do three things:

  1. Start an empty project on Github and clone the repo to our computer
  2. Take an existing project and push it to github
  3. Clone an existing repository on Github and put it on our computer.

We are not going to:

  • Have an in-depth explanation of what git is
  • Talk about how it works on a complex level.

For all projects not yet created / on Github

So, you always want to create the project on Github first (if you already have files on your computer, don’t worry, we deal with files next). Make an account on Github if you don’t have one, then click the green button “New Repository.”

On the next page, give your project some kind of cool name, like “gitexample”. Give it whatever description you want, and leave the README box unchecked. Reference shot:

Click the “Create Repository” button at the bottom of the screen.

Normally, we would use ssh because in the real world it is much more convenient, but ssh is a whole different thing so we’ll be using https and typing our password each time we want to move files back and forth between Github and our computer.

On the next screen, click the HTTPS button under “Quick setup — if you’ve done this kind of thing before”. You should see this screen (Note the https: at the beginning of the github link string):

How to create the project itself / move out project to github

So, now we have a place to actually put the files on Github (in the screenshot, that would be the string https://github.com/Rob117/gitexample.git).

If you have no files on your computer (Fresh start):

First go to the folder where you want to actually have the project reside on your computer. For example, if you want the project folder to be Documents/gitexample, make sure you cd Documents/gitexample before starting the following.

The format is:

Comment about following commands
lines that look like this are terminal commands

This simply creates a file in the folder we are currently in. The file name is README.md, and the contents just read # gitexample
echo "# gitexample" >> README.md

Tell the git system we’ll be tracking changes here
git init

Tell git that we want to add the file that we just created so we can save it to our system
git add README.md

Save all the files we just added (currently just the one) – note, the “first commit” can be anything you like
git commit -m "first commit"

Tell git “The link after origin is where we want to push and pull files from.”
PLEASE REPLACE https://github.com/Rob117/gitexample.git with your own link from earlier
git remote add origin <https://github.com/Rob117/gitexample.git>

push the file we just made to the remote repository we created!
git push -u origin master

It will prompt you for your password. That’s it! When you go check the repository page on Github, you should see your file!

If you have files on your computer

Go to the folder with the project files in your terminal cd Documents/MyFolderName
lines that look like this are terminal commands

Tell the git system we’ll be tracking changes here
git init

Tell git that we want to add all the files in this folder to our git repository for tracking.
git add .

Save all the files we just added – note, the “first commit” can be anything you like
git commit -m "first commit"

Tell git “The link after origin is where we want to push and pull files from.”
PLEASE REPLACE https://github.com/Rob117/gitexample.git with your own link from earlier
git remote add origin <https://github.com/Rob117/gitexample.git>

push the file we just made to the remote repository we created!
git push -u origin master

It will prompt you for your password. That’s it! When you go check the repository page on Github, you should see your files from your project.

Pulling from an existing project

This one is actually super easy.
Go to where you want the folder to reside on your computer. For example, if you want the file path to be Documents/Project, cd Documents

Then open the project GitHub Page (example) and notice the green “Clone or download” button. Click that, then change it to https (or ssh, depending on what your boss tells you). It will give you a string like https://github.com/Rob117/serverless-twitter-email.git

Then just simply type in terminal git clone <https://github.com/Rob117/serverless-twitter-email.git>, using your own string.

The project folder will be automatically created, and all the files transferred into it!

And that’s the basics of git transferring files. If anything I’ve written is unclear, please let me know so I can refine the process.