# Initialize a new repository
git init
# Check the status of the repository
git status
# Check the status of the repository
git status
# Show changes in the working directory
git diff
# Add a single file to the staging area
git add filename.txt
# Add all files to the staging area
git add .
# Commit staged changes
git commit -m "Initial commit"
# View commit history
git log
# Clone an existing repository
git clone https://github.com/username/repository.git
# View the commit history in the repository
git log
# View the commit history with a specific format
git log --oneline
# Create a new branch
git branch new-branch
# Switch to the new branch
git checkout new-branch
# Alternatively, create and switch in one command
git checkout -b new-branch
# Switch to the branch you want to merge into
git checkout main
# Merge another branch into the current branch
git merge new-branch
# Resolve conflicts, if any
# Delete a local branch
git branch -d new-branch
# Delete a remote branch
git push origin --delete new-branch
# Stash changes that are not yet committed
git stash
# List all stashes
git stash list
# Apply the latest stash
git stash apply
# Add a remote repository
git remote add origin https://github.com/username/repository.git
# Push changes to the remote repository
git push origin main
# Pull changes from the remote repository
git pull origin main
# Check remote repository URLs
git remote -v
# Undo changes in the working directory (before commit)
git checkout -- filename.txt
# Undo the last commit (keep the changes staged)
git reset --soft HEAD~1
# Undo the last commit (remove changes)
git reset --hard HEAD~1
# Rebase a branch onto another branch
git checkout feature-branch
git rebase main
# Resolve conflicts if they occur during the rebase
# Apply a specific commit from another branch
git cherry-pick <commit-hash>
# After cherry-pick, commit if necessary
# Create a new tag
git tag v1.0
# Push tags to the remote repository
git push origin v1.0
# List all tags
git tag
# Checkout a specific tag
git checkout v1.0
# Reset to a specific commit (and delete changes)
git reset --hard <commit-hash>
# Revert a commit (create a new commit that undoes the changes)
git revert <commit-hash>
# After a merge conflict, Git will mark the conflicting files
git status
# Open the conflicting file and manually resolve conflicts
# After resolving, stage the file and commit the merge
git add filename.txt
git commit
# Combine multiple commits into one (during rebase)
git rebase -i HEAD~3
# Mark the commits you want to squash
# Change 'pick' to 'squash' for the commits to combine
# After finishing, you'll have one commit containing all the changes