
Git命令
远程仓库地址
查看远程仓库地址
shell
git remote -v
设置远程仓库地址
shell
git remote set-url origin <new-url>
查看config配置
shell
git config --list
拉取指定分支代码
拉取远程的dev分支到本地
shell
git clone -b dev git@gitee.com:lzh1995/git-demo.git
本地创建分支并切换
shell
git checkout -b 新分支名
分支
查看远程分支
shell
git branch -r
查看本地分支
shell
git branch
切换本地分支
shell
# 切换到名为branch_name的branch
git checkout branch_name
# 创建并切换到名为branch_name的branch
git checkout -b branch_name
拉取远程地址的分支并创建本地分支
比如远程分支有10个,我们想在本地全部给拉取下来。
shell
for branch in $(git branch -r | grep 'origin/' | grep -v '\->'); do
git checkout -b "${branch##*/}" "$branch";
done
将本地全部的分支推送到远程
shell
git push --all origin
删除远程分支文件保留本地文件
由于粗心,没有仔细检查,忘记把1.txt 文件给忽略掉,没有写在.gitignore中, 导致推送到了git仓库,现在我已经将1.txt写到了.gitignore中。应该如何做?
- 先从 Git 仓库删除(保留本地文件)
shell
# 如果是文件的话需要这样写
git rm --cached 1.txt
# 如果是文件夹的话需要这样写 递归删除 Git 跟踪但保留本地文件
git rm -r --cached xx/
- 提交这次删除操作
xml
git commit -m "Remove 1.txt from repository"
- 推送到远程仓库
shell
git push