Git
Basic Commands
Check GIT version
git --version
Clone a repository
git clone <repository_url>
Initialize a new repository
git init
Check repository status
git status
Add files to staging area
git add <file_name>
Add all files to staging area
git add .
Commit changes
git commit -m "<commit_message>"
Push changes to the remote repository
git push origin <branch_name>
Pull the latest changes from the remote repository
git pull
Branching & Merging
Create a new branch
git checkout -b <branch_name>
Switch to a branch
git checkout <branch_name>
List all branches
git branch
Merge a branch into the current branch
git merge <branch_name>
Delete a branch locally
git branch -d <branch_name>
Delete a branch remotely
git push origin --delete <branch_name>
Stashing & Cleaning
Stash uncommitted changes
git stash
Apply stashed changes
git stash apply
List all stashes
git stash list
Drop a stash
git stash drop
Clean untracked files
git clean -f
Remote Repository Management
Add a remote repository
git remote add origin <repository_url>
View remote repository URLs
git remote -v
Change the remote URL
git remote set-url origin <new_repository_url>
Remove a remote
git remote remove <name>
Miscellaneous
View commit history
git log
View commit history with one-line summary
git log --oneline
Undo the last commit (keep changes in working directory)
git reset --soft HEAD~1
Hard reset to a specific commit
git reset --hard <commit_hash>
Check GIT configuration
git config --list
Last modified: 08 September 2024