git在分支上创建目录和文件

时间:2023-03-08 20:48:24

创建一个空目录,在其中初始化git

git init

创建一个新文件,此时默认在master分支上

touch file1.txt

add到staging area

git add file1.txt

提交变化

git commit -m 'the first commit'

创建一个新的分支

git branch newBranch

切换到新的分支

git checkout newBranch

在新的分支newBranch下创建目录和文件

mkdir folder
touch folder/file2.txt

在新的分支newBranch下add刚添加的目录和文件

git add folder

提交变化

git commit -m 'second commit'

来到默认分支

git checkout master
此时,在newBrach分支上创建的folder目录是不可见滴。