1.Register in https://github.com/
2.Set SSH Key
- Set up ssh key
ssh-keygen -t rsa -C "hans@qq.com"
copy the context of ~/.ssh/id-rsa.pub to github/setting/ssh-key, check ssh.
$ ssh -T git@github.com
Hi tianqixin! You've successfully authenticated, but GitHub does not provide shell access.
- set up global parameters.
git config --global user.name "Hans"
git config --global user.email "hans@qq.com"
3.Upload your source code
- Install git in local server
sudo apt-get install git
- Create your file to upload
touch hello.txt
git add hello.txt
or
git add ./ //add all the files in this directory
- Check status
git status
- Commit
git commit -m "hello"
- Push to remote github
- Check remote repository
$ git remote
origin
$ git remote -v
origin git@github.com:tianqixin/runoob-git-test.git (fetch)
origin git@github.com:tianqixin/runoob-git-test.git (push)
Create or link a remote repository with a name.Generally we set the master as “origin”.
git remote add origin git@github.com:Hans/hello1111111.git
git remote rm origin
Push to github
If you push at first time:
git push -u origin +master
else if you continue to push:
git push
Sometimes you need below command if you have some new files.
Clone files to from github
git remote add origin https://github.com/Hans/hello1111111.git
4.Download files from github
git clone https://github.com/Hans/hello1111111.git