git: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库

    1. 建立一个新仓库,为了避免错误,直接创建 .gitignore, README.md等文件。 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.

      git: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库
      git: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库
    2. 打开终端。Open Terminal.
    3. 转换到想要上传的项目目录。Change the current working directory to your local project.
    4. git 初始化。Initialize the local directory as a Git repository.
      git init
    5. git 添加当前项目文件。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'.
    6. 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.
    7. 找到 git 仓库地址。At the top of your GitHub repository’s Quick Setup page, click

      git: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库
      git: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库
    8. 复制 git 仓库地址。to copy the remote repository URL.
    9. 在终端运行下面代码: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
    10. push 代码: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

 如果必要,可以有以下设置:

#全局 
git config --global user.email "justcode@ikeepstudying.com" 
git config --global user.name "ikeepstudying" 

#本目录 
git config user.email "justcode@ikeepstudying.com"
git config user.name "ikeepstudying"

两个选一个即可,不过我个人不用全局。

更多 git 参考:

Shell:自动无密码提交git, cron git push with ssh key, 无密码提交git 到 Bitbucket或者GitHub

Linux:命令行git简单使用, git指令, 命令行操作git

git-ssh 配置和使用

多git帐号的SSH key切换

 

本文:git: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库

Leave a Reply