背景简介
使用Git 初始化新项目并推送至指定仓库。
环境信息
- Git 已安装 【Git - Debian 12 安装】
详细步骤
第一步: 初始化项目
$ cd path/to/your/project
$ git init
- 查看初始化结果
$ ls -alh
total 12K
drwxrwxr-x 3 henrylin henrylin 4.0K 3月 7 13:59 .
drwxr-x---+ 28 henrylin henrylin 4.0K 3月 7 13:59 ..
drwxrwxr-x 7 henrylin henrylin 4.0K 3月 7 13:59 .git
-rw-rw-r-- 1 henrylin henrylin 0 3月 7 13:59 test
第二步: 添加远程仓库
$ git remote add origin <repository-url>
第三步: 添加文件到暂存区
- 查看文件状态
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
test
nothing added to commit but untracked files present (use "git add" to track)
- 添加所有文件
$ git add .
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test
第四步: 提交变更
$ git commit -m "Initial commit"
[master c3ed6c5] Initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test
第五步: 推送至仓库
$ git push -u origin master
Username for 'repository-url': your_user_name
Password for 'https://your_user_name@repository-url':
枚举对象中: 25, 完成.
对象计数中: 100% (25/25), 完成.
使用 8 个线程进行压缩
压缩对象中: 100% (24/24), 完成.
写入对象中: 100% (25/25), 175.71 KiB | 3.31 MiB/s, 完成.
总共 25(差异 1),复用 0(差异 0),包复用 0
remote: . Processing 1 references
remote: Processed 1 references in total
To https://repository-url/react-app-demo.git
* [new branch] master -> master
分支 'master' 设置为跟踪 'origin/master'。
以上便是本文的全部内容,感谢您的阅读,如遇到任何问题,欢迎在评论区留言讨论。