前言
管理你的代码–git
1. 安装
sudo apt-get install git
2. 配置邮箱
git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"
git config --list
3. 创建repository
yanglu@ubuntu:~/Desktop$ git init Data_structure
Initialized empty Git repository in /home/yanglu/Desktop/Data_structure/.git/
yanglu@ubuntu:~/Desktop$ cd Data_structure/
yanglu@ubuntu:~/Desktop/Data_structure$ gedit README
yanglu@ubuntu:~/Desktop/Data_structure$ gedit first.cpp
yanglu@ubuntu:~/Desktop/Data_structure$ git add README
yanglu@ubuntu:~/Desktop/Data_structure$ git add hello.cpp
yanglu@ubuntu:~/Desktop/Data_structure$ git commit -m "data structure"
[master (root-commit) 7815769] data structure
2 files changed, 8 insertions(+)
create mode 100644 README
create mode 100644 hello.cpp
4. 上传github
yanglu@ubuntu:~/Desktop/Data_structure$ git remote add origin https://github.com/Data_structure.git
yanglu@ubuntu:~/Desktop/Data_structure$ git branch -M main
yanglu@ubuntu:~/Desktop/Data_structure$ git push -u origin main
报错
fatal: unable to access 'https://github.com/': Failed to connect to github.com port 443: Connection refused
解决方法
step1:检查邮箱是否与github邮箱一致
step2:在hosts文件尾部添加github可以响应的ip
sudo vi /etc/hosts
尾部添加
# GitHub Start
140.82.113.3 github.com
140.82.114.20 gist.github.com
151.101.184.133 assets-cdn.github.com
151.101.184.133 raw.githubusercontent.com
151.101.184.133 gist.githubusercontent.com
151.101.184.133 cloud.githubusercontent.com
151.101.184.133 camo.githubusercontent.com
151.101.184.133 avatars0.githubusercontent.com
199.232.68.133 avatars0.githubusercontent.com
199.232.28.133 avatars1.githubusercontent.com
151.101.184.133 avatars1.githubusercontent.com
151.101.184.133 avatars2.githubusercontent.com
199.232.28.133 avatars2.githubusercontent.com
151.101.184.133 avatars3.githubusercontent.com
199.232.68.133 avatars3.githubusercontent.com
151.101.184.133 avatars4.githubusercontent.com
199.232.68.133 avatars4.githubusercontent.com
151.101.184.133 avatars5.githubusercontent.com
199.232.68.133 avatars5.githubusercontent.com
151.101.184.133 avatars6.githubusercontent.com
199.232.68.133 avatars6.githubusercontent.com
151.101.184.133 avatars7.githubusercontent.com
199.232.68.133 avatars7.githubusercontent.com
151.101.184.133 avatars8.githubusercontent.com
199.232.68.133 avatars8.githubusercontent.com
# GitHub End
再次运行
git push -u origin main
,输入名字和密码即可。
总结
git还需要多使用才能掌握