last hacked on Aug 23, 2017

Utilizing *GitHub* is an important and powerful tool for *data scientist* and coders alike. This powerful *open-source* tools allows for control-versioning, collaborating, and sharing code for a wide variety of projects. I obviously can't go into every intricate detail and it would benefit you to look at documentation provided by [GitHub](https://git-scm.com/) and [git](https://git-scm.com/), but I'll do a quick run through of useful tools for you and your team when utilizing *GitHub* and you want to start integrating *git* into your workflow.
# Understanding Git Work Flow ## Table of Contents + [Setting Up Git](#setup) + [Preliminary Set-Up for Local Machine](#presetup) + [Initializing local repository](#gitinit) + [Adding Files to Local Repo](#vireadme) + [Publising on GitHub](#publgit) + [Create repo on GitHub](#creategitrepo) + [Results](#results) ## <a name='setup'></a>Setting Up Git This section I won't describe the process I'll provide the link to *GitHub*'s documentation which would be redundant for me to repeat on here. Here's the [link](https://help.github.com/articles/set-up-git/) Refer to the section titled **Setting Up Git** and follow the three set up links. Now that you have *git* set up on your computer with proper credentials, check to see if it installed correctly by running the following command on your terminal. $ git --version ### Terminal Output git version X.X.X ### Note for Windows If you are utilizing *git* for *Windows*, you simply have to download the latest windows version available. And if you wanted to make it available on the *Command Prompt* you would have to set your environment path with the environment name `git` as such: C:\Program Files\Git\git-cmd.exe Or else you'll receive this error: 'git' is not recognized as an internal or external command, operable program or batch file. ## <a name='presetup'></a>Preliminary Set-Up for Local Machine Before you initialize a local repository you should organize your local machine to help declutter and fast finding of future projects. First you should be comfortable with using basic command line commands. We will start with the opening a terminal on your machine using `Ctrl`+`Alt`+`T` for *Ubuntu* or `Win`+`R` and type `cmd` then press `Enter` (*Mac* will be added later on). You should be in your home directory: rxe: $ Now you should go ahead and create a *myProjects* folder to help with organization if you don't already have one: $ mkdir myProjects Now go into that folder: $ cd myProjects Obviously you won't have anything in there so let's create a project you will be working on called `testProject` $ mkdir testProject Now go into the directory $ cd testProject **Note**: I am using Linux so the commands should translate well with **Macs**, if you have **windows** go google it. ## <a name='gitinit'></a>Initializing Local Repository Now we want to initialize a local instance of the repo that you will be using on *GitHub*. We do this by running the following command (keeping in mind the working directory is /home/rxe/myProjects/testProject) git init Once you run this command you will be greeted with this output ### Terminal Output Initialized empty Git repository in /home/rxe/myProjects/testRepo/.git/ You have created a *.git* subdirectory in the project root, this contains metadata for this project repo. You can check this by running the following command: $ ls -a ### Note for Windows $ dir /a ### Terminal Output . .. .git Now we will create a README file to commit to our not-yet-created repository on *GitHub* ## <a name='vireadme'></a>Adding Files to Local Repo Our next step is to add files to our local repository to later add to the *GitHub* repository. I will do this utilizing `vi` although I do recommend looking into [Sublime Text](https://www.sublimetext.com/), [Notepad++](https://notepad-plus-plus.org/), or [emacs](https://www.gnu.org/software/emacs/). $ vi README.md Here we're creating a *README* file in *markdown* format. I input into the file the following syntax, pressing `i` to insert text into the *markdown* file. # Test Repo ## Practicing Committing to GitHub using git ignore this is a test Then we write the changes into the file using: :wq Again this syntax isn't important if you're using an external text editor. You can just create a markdown file and add this text then save in the *testProject* repo. ### Note for Windows *Vim* isn't natively installed so I recommend using the command: $ notepad README.md Now that we have work to commit we are ready to publish on *GitHub* ## <a name='publgit'></a>Publishing on GitHub Our local repository has some files we would like to include in our *GitHub* repo. So we begin this by adding all appropriate files as such $ git add README.md Or if everything in your directory belongs into the *GitHub* repo do the following: $ git add --all . Next we commit our changes and we add a comment as to what we just did to give people context. $ git commit -m 'created a README file' ### Note for Windows When utilizing the `commit` functionality I noticed that using single quotes would reject my commit comment so instead use: $ git commit -m "created a README file" I will advise to constantly check the status of your repo to ensure there are no conflicts by using the command $ git status ## <a name='creategitrepo'></a>Create repo on GitHub Now that we have a local instance of the repo on our machine let's create a repo on *GitHub*. Click on the **New Repository** button in *GitHub*, in this example we will be calling it *testRepo*, noting that we won't initialize with a **README** file because this will cause conflicts. Create the repository and grab the **web URL**. It should look like this https://github.com/raviolli77/testRepo.git Now going back to the terminal line use the following command git remote add origin https://github.com/raviolli77/testRepo.git You will be asked for credentials relating to your *GitHub* account, go ahead and fill those in. And now you are ready to push the changes from the local instance to the remote instance. You do this as follows: git push -u origin master ### Terminal Output Counting objects: 3, done. Writing objects: 100% (3/3), 231 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/raviolli77/testRepo.git * [new branch] master -> master Branch master set up to track remote branch master from origin. ## <a name='results'></a>Results If you go to your repo on *GitHub* which in my case is linked as https://github.com/raviolli77/testRepo, you will see all the changes you made from your local machine on this repo!


keep exploring!

back to all projects