题记:团队中大多数成员使用 sourceTree 和 github 两款 git 工具,然而大家对于图形化工具提供的 reset,checkout,revert 功能点并不是很了解,甚至于混淆,然后凭借猜测去使用。功夫不负有心人,在尝试过多次冲突处理或分支开发的坑后,终于形成了自己的一套使用方式,可喜可…
April 14, 2018
git: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库
-
- 建立一个新仓库,为了避免错误,直接创建 .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. - 打开终端。Open Terminal.
- 转换到想要上传的项目目录。Change the current working directory to your local project.
- git 初始化。Initialize the local directory as a Git repository.
git init
- 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'.
- 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.
- 找到 git 仓库地址。At the top of your GitHub repository’s Quick Setup page, click
- 复制 git 仓库地址。to copy the remote repository URL.
- 在终端运行下面代码: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
- 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
- 建立一个新仓库,为了避免错误,直接创建 .gitignore, README.md等文件。 Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or
如果必要,可以有以下设置:
#全局 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: 命令行添加项目到 git 仓库, Adding an existing project to GitHub using the command line, 添加项目到 git 空仓库