DEV Community

Cover image for Step By Step Guide To Push Your First Project On GitHub
Code Hunter
Code Hunter

Posted on

Step By Step Guide To Push Your First Project On GitHub

Depending on your situation, or what you are trying to do, there are probably a dozen ways to push your source code for for the first time to GitHub. But I’m these six git commands are the only ones I use.
My situation is a little simpler. I use GitHub just for my personal work. I don’t really collaborate with anyone. I don’t use branches. I work on the master directly. I use Windows. If this is your situation as well, then this post might help you.

Set Up Your Environment

I assume that you have already set up your environment to use the git commands. If not, make sure you do the following first:

  • Install Git SCM on your computer to enable you to use git on the command line.
  • Register at GitHub. Then, create an empty repository.

The Six Commands

I run these six commands in this order:

git init
Enter fullscreen mode Exit fullscreen mode
git add -A
Enter fullscreen mode Exit fullscreen mode
git commit -m “your message”
Enter fullscreen mode Exit fullscreen mode
git remote add origin https://github.com/username/reponame.git
Enter fullscreen mode Exit fullscreen mode
git pull –rebase
Enter fullscreen mode Exit fullscreen mode
git push -f origin master
Enter fullscreen mode Exit fullscreen mode

git init

Initializes and prepares your directory for git. Suffice it to say that you need to open a command prompt or PowerShell » CD to your source code directory » type git init and Enter. You can execute git status at any point in time to see where you’re at in the process.

git add -A

Prepares all changes on staging. The -A means all changes are staged including edits, additions, and deletes. I do this because I don’t have to think!

git commit -m

Commits all the changes. After commit, you are ready to push to GitHub.

git remote add origin

Associates your directory with a remote git server and repo. The URL of your repo is that URL that you see when you click the Clone or download button. You can execute git remote -v to verify that your directory has been associated with your remote repo.

git pull –rebase

This step is somewhat controversial. I only use this because I am pushing directly to a master, so I need to pull from the remote first before pushing. In fact, if I don’t use this, it won’t let me push! According to Atlassian, it’s like saying, “I want to put my changes on top of what everybody else has done.” So, this is perfectly fine for my situation.

git push -f origin master

Because I did a pull –rebase, I need to force or use the -f directive.

That’s it

Let me know what you think!

Top comments (0)