First things first,install git.

——Stop BBing if you have not even installed the git.

Install git(may need root permission)

  • Ubuntu/Debian/Deepin: apt install git
  • Arch/Manjaro:pacman -S git
  • Free BSD:pkg install git
  • macOS:brew install git
  • Windows:Click HERE to download the installer

Run git –version to make sure that git is installed on your device.

Put your codes to a folder and initialize

Now you can copy+paste all your code that need to be pushed to the Github in your new folder.Then run a terminal in this folder.

Using git init to initial your local repository.

And do not forget to add a new repository in your Github account.Once you added a new repository to your Github,you will get a repository-link just like this:

https://github.com/YourGithubID/YourRepoName.git

Now,run git remote add origin $YourRepoLink to link your remote repository to the local one.

Add your files to staging area

Use git add $Filename to add the files you need to staging area. Or you can use git add . (THERE IS A DOT AT THE END) to add all your files。

Then run git status to check the files in your local repository.

Run git commit -m ‘$YourCommits’ to add some commits to this submit.

Push your code to Github

First of all,use git pull origin master to pull your online repository.

Use git push origin master to submit your files to Github.

There are some cases that you will meet the ERROR that refusing to merge unrelated histories when you pull.You can try git pull origin master –allow-unrelated-histories to allow merging two unrelated branches.(At the first time,the online repository is empty but the local one have some files,so of course they are unrelated).

Now you can check your new repository on the Github.

Done,enjoy.