Pushing an existing repository to Github.
Tags: git, github, beginners
Published: 2020-01-27 09:40:12

### **What is Github?**
Github is a web-based Git repository hosting service that primarily offers distributed version control and source code management functionality of git. It was developed by Chris and Tom, When they started working on GitHub in late 2007, Git was largely unknown as a version control system.


Every developer always finds GitHub confusing at first, but don’t be frightened, these few steps will help you push an existing repository to GitHub.

Before we go on, I’m just going to assume you’ve already installed Git on your desktop and have a GitHub profile.

I’m going to introduce you to some keywords/terminologies that are common when talking about git:


**Command-Line:** This is a computer-based program. It is a text interface for your computer. It's a program that receives commands which it passes on to the computer's operating system to run. This is where we input Git commands. On a Mac or Linux machine, It’s called Terminal, while on Windows, It’s called Command Prompt. 

**Repository:** Also called “repo” for short, repository is a storage location for software packages, a directory or storage space where your projects can “live.” It could be local on your desktop or on your Github space. It can also contain different contents like text, images, videos and so on.

**Version Control:** This is the sole purpose of Git. Just like when you have a text document, you can override every saved file with a new save, or you can save different versions. With Git, you don’t have to save different versions. It has a time track of every point in time you make a change to your project’s directory on Git.

**Commit:** This is the command that gives Git its power. When you commit, you are taking a “snapshot” of your repository at that point in time, giving you a checkpoint to which you can reevaluate or restore your project to any previous state.


**Git init:** The git init command creates a new Git repository or reinitializes an existing one in your project’s directory. This is very important because other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.



#### **So enough with all the theories, time to get practical**.


  Create a repo by clicking on the “New” button on the GitHub home.

![First Step](https://thepracticaldev.s3.amazonaws.com/i/1obxwv8bmvw0jad5c9oi.jpg)


  Name your repo. You can add a read-me file later, but you can’t do that right now because we are pushing an existing project to GitHub, You’ll have to do that locally.

![Second Step](https://thepracticaldev.s3.amazonaws.com/i/7oyjz22t913k5y6d0ap6.png)

Click on the “Create repository” button.


  Copy the URL of your repo

![Third Step](https://thepracticaldev.s3.amazonaws.com/i/fu6nmzos3hhmpqflr29n.png)

Make sure you copy the URL, not the SSH key (This can only work when you’ve created an SSH key from your desktop).

#### **Open the Command line**.


  Go to your project directory, make sure you are in the right directory (i.e., the project directory you want to initialize git on). Don't worry If you don’t know how to use the command line, just follow along.


  On your command line or terminal, type in **git init**.

![git init]
(https://thepracticaldev.s3.amazonaws.com/i/x8ncmmnfpeo49mmmw694.png)


  Type in: **git remote add origin** (followed by THE URL YOU COPIED)

![git remote](https://thepracticaldev.s3.amazonaws.com/i/vbn7j0tpeeaf8felythq.jpg)


  Type in: **git add .** or **git add -a** to add all your files for commit, the dot(.) represents all, and it performs the same action as using the -a flag.

![git add](https://thepracticaldev.s3.amazonaws.com/i/9rrai9qkfarpiuwzgveq.jpg)


  Time to commit all your hard work. Type in **git commit -m “YOUR COMMIT MESSAGE”**. It’s good practice to write your commit messages in the present tense, e.g., **git commit -m “Fix login error on admin page”**.

Basically,
+ Write in the present tense
+ First-line should be capitalized, 50 characters or less, no period
+ The rest of the message should support the first line, if necessary.

![git commit](https://thepracticaldev.s3.amazonaws.com/i/c1ofjdvb3oxdvt3elpes.png)


  Push your hard work for the world to see. Type in: **git push origin master**. to push your work to GitHub.

![git push](https://thepracticaldev.s3.amazonaws.com/i/mfk9nnbbvvfkrdrrp66g.png)


So, there you have it, people. It’s pretty easy, Just know the basic commands and you are ready to rock. 

Thanks for reading. If you have suggestions and or additions, please leave a comment. Or, if you’d like to chat about programming or tech-related stuff, slide into my Dm on twitter @ayomide_bajo. Have a great day!