GIT常用命令

#本地初始化

git init

 #添加到暂存区

git add .

 #确认提交

git commit -m "comment"

 # 关联远程仓库

git remote add origin ssh://git@hupz.com:/home/git/gitrepo/gittest.git

 # 推送到远程仓库

git push origin master

 # 强制推送

git push -u origin master -f

# 修改remote节点,先删后加

git remote rm origin
git remote add origin ssh://git@hupz.com:/home/git/gitrepo/gittest.git

# 回退到最近的commit 节点,用于在代码commit之前回退

git reset --hard

# 创建新的分支

git branch -b branch_name

# 删除某分支

git checkout master  # 切换到其他分支

git branch -d branch_name

# 查看关联的远程仓库的名称

git remote

# 查看关联的远程仓库的详细信息

git remote -v

# git_url 为你的远程仓库的 url,可采用 http 协议或 ssh(git) 协议

git remote add origin <url>

# 从远程仓库获取代码

git clone ssh://git@hupz.com:/home/git/gitrepo/gittest.git

git clone https://hupz.com:/home/git/gitrepo/gittest.git

# 从远程仓库更新分支

git fetch origin master

# 对比本地与远程的区别

git log -p master..origin/master

# 合并

git merge origin/master

# 解决CRLF警告问题

git config --global core.autocrlf false

——————————————————————

参考文档:

https://hupingzhi.cn/post/21/

原文地址:https://www.cnblogs.com/hupingzhi/p/12000149.html