Configure github with mac and upload an existing project to github by using terminal

本文介绍如何通过SSH公钥配置实现GitHub上的代码安全访问,并指导如何将本地项目同步到GitHub仓库中,包括SSH密钥的创建、配置及测试,以及使用Git命令初始化本地仓库、添加文件、提交更改并推送到远程仓库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Configure ssh with public key

  1. Open Terminal.
  2. Create a new ssh key (change with your email address)
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. Login github with your account. Settings->SSH and GPG keys->New SSH key
    Fill out the form (title and your public key)
  4. Test your SSH connection with following line. If the SSH key is successfully connected, the icon of the key will become green.
    ssh -T git@github.com


New Project with github

  1. Register the github account.
  2. New repositories in the github.

Adding an existing project to GitHub

  1. Initialize the the local directory as a Git repository.
    git init

  2. 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'.
  3. 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.
  4. At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.ill 
  5. 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
  6. Push the changes in your local repository to GitHub.
    git push -u origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin

TroubleShooting

  1. If you cannot push the code, it probably be the README.md were not in your directory.
    Solution:
    Before push your code, use the following line.
    git pull --rebase origin master


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值