Preface

With the supervision and speed limit getting more and more serious in BaiDu Cloud Store, it is the high time for us to look for a relatively free cloud store site with a reasonable speed limit. Also, for important files, a good backup tool is urgently needed. So using github with git seems a good choice to me.

In this passage, I will document the detailed process to add an existing git repository into a newly-created github repository.

Preparations

First a git local repository (at path /foo/markdown, for example) with some files (like /foo/markdown/git.md) and a cloud github repository (like foo/markdown) is needed. Of course you must have full permissions for the two repository.

Then, you need to add the SSH key of your computer or local account to your Github account. If not, you should generate an SSH key and add it to the ssh-agent and then add the key to your Github account. Check the key regularly as GitHub will remove any SSH key in your account not used for more than a year.

Main Processes

If there's already some files in your remote github repository, you need to create a new directory and change into it and create a new repository. If not, just do all the operations in your local repository.

Fiest, use git remote add 名字 链接 to add the 链接 of your remote repository in the remote URL list of your local repository under the name of 名 字 (usually origin for the first one). The 链接 can be in either of two forms below.

  1. [email protected]: 作者名 / 仓库名: this form will use SSH to connect. So you need not to input the username and passphrase every time you want to push/pull as long as the SSH key of your computer or account is stored at your GitHub account.
  2. The regular URL used in the browser to access your repository: it need no SSH key but will force you to input username and password every time.

After which, git fetch and git pull --set-upstream 名字 分支 to pull the file in the remote repository(if any).

Move your file to the directory if you create the repository at a new directory.

git add and git commit.

Finally, use git push to push your new commit to GitHub.