[Github] Use git to manage code on github [Linux]

        Problem description: Under Linux server, you need to use git to manage projects and perform synchronization backup on github.

1. Create a warehouse on github. There are all tutorials on the Internet for this step. Then you will have a library like the following:

2. Install git on your Linux. There are all tutorials on the Internet, so just take a look.

3. Bind git user. What needs to be bound in this step is your github username and email.

# 配置用户名、邮箱
git config --global user.name "xxx"
git config --global user.email "[email protected]"
# 查看config信息
git config --list

4. In order for your host to connect to GitHub without a password, configure the key generated by your computer on GitHub.

# 进入ssh配置目录
cd ~/.ssh
# 生成密钥,过程一路回车啥也不输
ssh-keygen -t rsa -C "[email protected]" 

5. Then you will get an id_rsa.pub file in the directory, open it and copy the contents.

        Paste it into github->settings->SSH....Keys. Use ssh -T [email protected] to test connectivity.

 6. At this step, you are ready to upload files. Just enter your project folder.

# 把这个目录变成Git可以管理的仓库
git init

# 添加一个文件
git add README.md 
# 添加当前目录下所有文件
git add . 

# 查看当前工作区的状态(需提交的变更)
git status

# 把文件提交到git仓库
git commit -m "随便写点备注" 

# 关联远程仓库,随便起个名字叫cxk吧,后面链接复制库的SSH链接
git remote add cxk [email protected]:xxx.git

# 往github上传个分支(如无远程主分支则创建,用于初始化远程仓库),分支名就起个xz吧,当然一般都叫
# master或者main,这个随意
git push -u cxk xz //将本地主分支推到远程

# 把github的分支合并整到主机
git pull cxk xz 

# 新电脑下载github项目
git clone [email protected]:xxx.git 

         Project SSH link here

         A project can have many branches (different versions). You can view them here. If you don’t find the one you uploaded, it may be in another branch. Click to open it and take a look:

 

Guess you like

Origin blog.csdn.net/weixin_42569673/article/details/123796618