Git基本

 

参考文献: GitLab実践ガイド(北山晋吾/棚井俊 著)

-- 1. 初期設定

git config --global user.name "Administrator"
git config --global user.email "Administrator@example.com"
git config --global init.defaultBranch main
git config --global color.ui auto

git config -l


-- 2. リポジトリ初期化

mkdir project01
cd project01
git init
LANG=C tree -a .

-- 3. ステージングエリアへ移行

echo "aaa" > aaa.txt
echo "bbb" > bbb.txt
ls -l

git status
git log --graph

git add ./aaa.txt

git status
git log --graph

 

-- 4. ローカルリポジトリへコミット

git status
git log --graph

git commit -m "a"

git status
git log --graph


コミット情報の変更
git commit --amend -m "aaa"

git status
git log --graph

 

-- 5. ブランチの作成

git branch --all
git branch feature
git branch --all

-- 6. ブランチの切替

git branch --all
git checkout feature
git branch --all

cat <<-'EOF' > aaa.txt
aaa
hoge
EOF

cat aaa.txt

git status
git log --graph

git add ./aaa.txt
git commit -m "hoge"

git status
git log --graph

 


-- 7. featureブランチのマージ

git checkout feature
cat ./aaa.txt
git checkout main
cat ./aaa.txt

git status
git log --graph

git merge feature

git checkout feature
cat ./aaa.txt
git checkout main
cat ./aaa.txt

git status
git log --graph

 


-- 8. リモートリポジトリの複製

cd ..


git clone https://${GITLAB_USER}:${GITLAB_TOKEN}@gitlab.com/group20240303/project02.git

ls -l

cd project02
git branch -a


-- 9. リモートリポジトリへの反映

echo fuga > fuga.txt

git status
git log origin/main --graph
git log --graph

git add -A
git commit -m "fuga"

git status
git log origin/main --graph
git log --graph

git push

git status
git log origin/main --graph
git log --graph

 

-- 10. 追跡ブランチへの更新反映
リモートリポジトリで画面からファイル削除

git status
git log origin/main --graph
git log --graph
ls -l


git fetch origin

git status
git log origin/main --graph
git log --graph
ls -l

 

-- 11. 作業ブランチへの更新反映


git status
git log origin/main --graph
git log --graph
ls -l

git merge FETCH_HEAD

git status
git log origin/main --graph
git log --graph
ls -l


-- 12. 追跡ブランチと作業ブランチへの更新同時反映
リモートリポジトリで画面からファイル追加


git status
git log origin/main --graph -n 3
git log --graph -n 3
ls -l

git pull


git status
git log origin/main --graph -n 3
git log --graph -n 3
ls -l