How to upload file to GitHub

sinclair
3 min readNov 6, 2020

For beginners who struggle with GitHub

GitHub is useful to save your project or to do the team project. However, using GitHub is sometimes tricky. I also felt the necessity to make up how to use GitHub from A to Z at least one time. Let’s start!

1) Open the terminal (MacOS Users) and go to the file containing your source file. I usually write ‘cd’ and then drag-and-drop the file. Then the local directory appears automatically.

2) git init

we should make git initializer. To make git track the folder, we should create .git folder with this command.

3) git status

You can check the statement of files with git

In this case, I didn’t write any code so there is nothing to commit lol

You can check the error when it doesn’t work out. You can also check if the file that you didn’t work on was modified with this command. It’s really useful command.

4) git add .

You can add file that you are going to manage version with git. This command will add every file that was modified to local repository.

5) git commit -m “message (you can write)”

-m is the option to write the message in one line. If you needed to write longer message then you can just use the command: git commit

6) git remote add origin {remote repository address}

origin is the nickname of the remote repository. You can change the name as you want. Usually, we use ‘origin’.

You can copy the github address for the repository address.

7) git push origin master

master is the name of the branch. Master branch is created when you make remote repository basically. When you wanna push to another branch, then you can just simply change the master as certain branch name that you wanna push. Like the below.

git push origin {name of the branch}

Finally you uploaded your local file to remote repository on GitHub!!

Those steps were for the first time when you created a new remote repository. We can omit some process, when you’ve already made the remote repository.

Move to the folder on the commander and then follow the steps below:

git add

git commit -m “message”

git push origin {branch name}

  • Error: failed to push some refs to ‘address’

I was struggled with this error for the first time. After I should have spent some time on google, I could come up with the solution.

You should pull first before you push your updates!

git push origin +master

add + before the branch name.

[Warning] This resets your remote git repository and then push new commit!

I could see all of my files were gone .. SO BE CAREFUL when you use this code!

--

--