Initialize a Repository
git init
Clone a Repository
git clone <repository_url>
Configure User Information
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Add Changes to Staging Area
git add <filename>
git add .
Commit Changes
git commit -m "Commit message"
Check Repository Status
git status
View Changes Made
git diff
View Commit History
git log
Create a Branch
git branch <branch_name>
Switch to a Branch
git checkout <branch_name>
Create and Switch to a New Branch
git checkout -b <new_branch_name>
Merge Branches
git merge <branch_name>
Pull Changes from a Remote Repository
git pull origin <branch_name>
Push Changes to a Remote Repository
git push origin <branch_name>
Fetch Changes from a Remote Repository
git fetch
Undo Changes in Working Directory
git checkout -- <filename>
Discard Changes in Staging Area
git reset <filename>
Undo Last Commit
git reset HEAD^
Configure Remote Repository
git remote add origin <repository_url>
Show Remote Repositories
git remote -v
Revert a Commit
git revert <commit_hash>
View Remote Branches
git remote show origin
Create a Tag
git tag <tag_name>
Delete a Branch
git branch -d <branch_name>
Delete a Remote Branch
git push origin --delete <remote_branch_name>
View Changes in a Specific Commit
git show <commit_hash>
Rename a File
git mv <old_filename> <new_filename>
List Tags
git tag -l
Cherry-pick a Commit
git cherry-pick <commit_hash>
Stash Changes
git stash
Apply Stashed Changes
git stash apply
Show Stash List
git stash list
Remove Stashed Changes
git stash drop
Clean Untracked Files
git clean -fd
Set Upstream Branch
git branch --set-upstream-to=origin/<branch_name>
Show Remote URL
git remote get-url origin
Show Last N Commits
git log -n
Interactive Staging
git add -i
Amend the Last Commit
git commit --amend
List Remote Branches
git branch -r
Conclusion
we have lots of more git commands but these are a few basic commands that we use on a regular basis, other commands will be discussed as we learn DevOps more in the future.