DEV Community

Bekka
Bekka

Posted on

Pushing an existing repository to Github.

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

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

Click on the “Create repository” button.

Copy the URL of your repo

Third Step

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

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

git remote

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

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

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

git push

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!

Top comments (8)

Collapse
 
cod profile image
N/A

Great tutorial .It really helped me out! A tip though is that the link for your twitter account doesn't actually redirect us there. You could try changing the link so more people(like me !) can link up with you on twitter.

Collapse
 
ayomide_bajo profile image
Bekka

Oh Okay,
I apologize for the mislead. It's actually my username on twitter.
A better way to go around it would be to copy the username without "@" and search for me on twitter.
I'm glad i could help! :D

Collapse
 
persimone profile image
Simone

Thank you so much! This was what I was looking for exactly :)

Collapse
 
ayomide_bajo profile image
Bekka

(I just saw this) happy to help!

Collapse
 
stegriff profile image
Ste Griffiths

Great first post, very informative, and definitely a question I've asked myself before! Welcome to Dev!

Collapse
 
ayomide_bajo profile image
Bekka

Thanks!

Collapse
 
dhatguy profile image
Joseph Odunsi • Edited

Nice post👍

But your DM is not open on twitter

Collapse
 
ayomide_bajo profile image
Bekka • Edited

I just changed the settings, Thanks for letting me know.