Git基础操作

# 1.安装git请参考之前的步骤
# 2.配置git
git config --global user.name "your name"
git config --global user.email "youemail@example.com"        # 注册时用的邮箱

# 创建新仓库
git init        # 初始化仓库
git clone https://github.com/user/repo        # 克隆远程仓库
git add filename        # 将文件添加到暂存区, 如果是  .   表示所有文件
git commit -m "commit message"            # 提交并写上备注
git status            # 查看当前暂存区状态
git diff filename            # 比较文件的差异
git log        # 查看历史
git reset --hard HEAD^            # 回退到上一个提交

# 3.分支操作
git branch branchname            # 创建新的分支
git checkout branchname            # 切换分支
git checkout -b branchname           # 创建并切换到新分支
git merge branchname             # 合并分支

# 4.远程仓库
git remote add origin https://github.com/user/repo        # 添加远程仓库
git push origin branchname        # 推送到远程仓库
git pull origin branchname            # 从远程仓库拉取
posted @ 2024-05-15 15:15  学python的菜鸟  阅读(2)  评论(0编辑  收藏  举报