Easy guide on how to push code to your GitHub Master branch

This post is a simple guide on how to push your code to GitHub from a command line. I am using a Mac, so it will be a little different for Windows users.

Let’s say if I have a folder called MinhDuong in this directory Documents/GitHub/MinhDuong

Step 1: on your command line, go to the same directory. In my case, it will look like this on my command line

Step 2: set up the remote URL

Basically, you want to make sure you will push the code to the right place. If you have a new repository, run this code:

git remote set-url origin "your repo URL goes here" (without the quotation marks)

If you are updating an existing repo, run “git remote -v” to figure out which repo you’re currently connected to. Here is how it looks on mine, exactly where I want it to be

Step 3: run “git status” to see if there are pending files to be pushed. If you’re pushing to a new repo, this shouldn’t matter much. However, if you are updating an existing repo, this will show the difference between the current folder on your local and the repo.

Step 4: now is the time to add files. If you want to add all files, run “git add .”. Remember the space and the dot after the word “add”.

Step 5: run

git commit -m "whatever comment you want"

Step 6: run

git push origin master

Then you are done.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.