Skip to content

Git commands

1. Configuration

Check git configuration

1
git config -l

Setup git username, email

Repository configuration

1
2
git config user.name "Huy Duong"
git config user.email "huy.duongdinh@gmail.com"

Global configuration

1
2
git config --global user.name "Huy Duong"
git config --global user.email "huy.duongdinh@gmail.com"

2. Branch

List branches

Local

1
git branch

Remote

1
git branch -r

Rename branch

Local

1
git branch -m <new_branch_name>

Remote

1
2
git push origin --delete <old_branch_name>
git push origin -u <new_branch_name>

Delete branch

Local

1
git branch -d <branch_name>

Remote

1
git push origin --delete <branch_name>

Create branch

1
git branch -b <branch_name>

3. Revert

Revert specific commit

1
git revert [--no-commit] <commit_id>

Revert file to specific commit

1
git checkout <commit_id> -- <file>

4. Rebase

Rebase interactive mode

1
git rebase -i <branch_name>

5. Submodule

Add submodule

1
2
3
git submodule add <remote_url>

git submodule add <remote_url> <folder>

Update submodule

1
git submodule update --init --recursive

Adjust commit date

1
git commit --amend --date="Wed Apr 19 18:00 2023 +0700" --no-edit