Balu
Balu Platform Engineer | Devops | Monitoring | CICD | ODD | SQL/NoSQL | ELK | AWS | Jhipster | Microservices | Agile | Scrum

Git - Common Commands

Git - Common Commands

Commit History

Show all commits, starting with the newest
1
git log
Commit history of specific file
1
2
3
4
git log -p <file_name>

# EXAMPLE
git log -p README.md
Commit hitory by user
1
2
3
4
git blame <file_name>

#Example
git blame README.md

Branches

List all local brnahces
1
git branch
List all local and remote brnahces
1
git branch -av
Switch to existing branch
1
2
3
4
git checkout <branch_name>

# Example
git checkout jinnabalu/testBranchName
Create a new branch
1
2
3
4
git checkout -b <brach_name>

# Example
git checkout -b jinnabalu/myNewBranchName
Delete local branch
1
2
3
4
5
6
7
git branch -d <branch_name>

# Example
git branch -d jinnabalu/myNewBranchName

## Force delete if not merged
git branch -D jinnabalu/myNewBranchName
Delete remote/origin branch
1
2
3
4
git push origin --delete <branch_name>

# Example
git push origin --delete jinnabalu/myNewBranchName

Pull and Push

Get latest from remote

pull: gets latest pushed by someone to the branch

1
git pull
Push local changes

push: push local cahnges to the remote branch

1
2
3
4
git push -u origin <branch_name>

# Example
git push -u origin jinnabalu/myNewBranchName

comments powered by Disqus