git

首次向远程服务器push

git和远程服务器之间的通信是通过ssh进行的,所以需要在本地生成ssh通信用的私钥和公钥,并将公钥添加到远程服务器的配置里面,否则会得到'Permission Denied (publickey)'的错误。
添加方法
This means, on your local machine, you haven’t made any SSH keys. Not to worry. Here’s how to fix:

  • Open git bash (Use the Windows search. To find it, type “git bash”) or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
  • Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users\[YOUR-USER-NAME]\.ssh\ on Windows)
  • Within the .ssh folder, there should be these two files: id_rsa and id_rsa.pub. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don’t show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git, GitHub, and BitBucket to recognize them by default.
  • To create the SSH keys, type ssh-keygen -t rsa -C "your_email@example.com". This will create bothid_rsa and id_rsa.pub files.
  • Now, go and open id_rsa.pub in your favorite text editor (you can do this via Windows Explorer or the OSX Finder if you like, tpying open . will open the folder).
  • Copy the contents–exactly as it appears, with no extra spaces or lines–of id_rsa.pub and paste it into GitHub and/or BitBucket under the Account Settings > SSH Keys. NOTE: I like to give the SSH key a descriptive name, usually with the name of the workstation I’m on along with the date.
  • Now that you’ve added your public key to Github and/or BitBucket, try to git push again and see if it works. It should!

More help available from GitHub on creating SSH Keys .

上传已经存在的项目到github

Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.

  1. Initialize the local directory as a Git repository.
$ git init
  1. Add the files in your new local repository. This stages them for the first commit.
git add .
# Adds the files in the local repository and stages them for commit.
# To unstage a file, use 'git reset HEAD YOUR-FILE'.
  1. Commit the files that you’ve staged in your local repository.
git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote repository. 
# To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
  1. Copy remote repository URL fieldAt the top of your GitHub repository’s Quick Setup page, click copy button to copy the remote repository URL.

  2. In Terminal, add the URL for the remote repository where your local repository will be pushed.

git remote add origin remote repository URL
# Sets the new remote
git remote -v
# Verifies the new remote URL
  1. Push the changes in your local repository to GitHub.
git push origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin

More help available from Adding an existing project to GitHub using the command line

从远程服务器下载

git clone https://github.com/tensorflow/models.git

更新远程代码到本地仓库

  1. 查看远程仓库
git remote -v

在这里插入图片描述
2. 更新远程代码到本地仓库

git fetch origin master

git fetch origin master 这句的意思是:从远程的origin仓库的master分支下载代码到本地的origin master

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值