diff is used to find differences between two files. For easier usage, combine it with -u:
diff -u file1 file2Compares two files line by line, displaying the differences side by side:
diff -u original.txt updated.txtpatch applies file differences to another file. Example:
- Save differences as a
.difffile:diff -u original.txt updated.txt > changes.diff - Apply the patch:
patch original.txt changes.diff
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config -l # Check current configurationEnable GPG signing for commits to enhance security:
- Generate a GPG key:
gpg --full-generate-key
- Add your GPG key to Git:
gpg --list-secret-keys --keyid-format=long git config --global user.signingkey <key_id> git config --global commit.gpgsign true
- Export your GPG key for public sharing:
gpg --armor --export <key_id>
- Verify GPG signing with:
git commit -S -m "Your message"
git init # Initialize a new repository
git add file.txt # Add a file to the staging area
git rm file.txt # Remove a file from the repositorygit commit # Commit changes (opens a text editor for the message)
git commit -m "Your commit message" # Commit with a message inline
git commit -a # Stage tracked changes and commit them in one step
git commit --amend # Modify the last commitgit status # Show the status of the working directory
git log # View commit history
git log -p # Show commits with changes (patch format)
git log --graph --oneline --all # View commit tree in one line
git log --stat # Display added/deleted statistics per filegit diff <branch1> <branch2> # Compare two branches
git diff <branch>:<file> # Compare a file from another branchgit diff # Show differences between working directory and index
git diff --staged # Show differences between staged files and last commit
git add -p # Interactively choose changes to stagegit reset HEAD <file> # Unstage a file
git reset -p # Interactively reset changes
git revert <commit_id> # Create a new commit to undo a previous one
git commit --amend # Amend the last commitgit clone <URL> # Clone a remote repository
git pull # Fetch and merge changes from the remote repository
git push # Push commits to the remote repositorygit remote -v # View configured remotes
git remote show origin # View details of a remote repositorygit branch # List branches
git branch <name> # Create a new branch
git branch -d <name> # Delete a branch
git branch -D <name> # Force delete a branchgit checkout <branch> # Switch to a branch
git checkout -b <branch> # Create and switch to a new branch
git merge <branch> # Merge a branch into the current branch
git merge --abort # Abort a merge in case of conflictsgit log --graph --oneline # View branch commit history in graph form
git branch -r # List remote branchesgit mv <old-name> <new-name> # Rename or move a filegit fetch # Download changes from the remote repositorygit commit -a -m "Message" # Stage and commit in one step