apt
, yum
, etc.).
sudo apt-get install git # Debian/Ubuntu
sudo yum install git # CentOS/Fedora
brew install git # Homebrew
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git --version # To confirm that git is installed and configured correctly on your machine
git init
Checking Status:
git status
Adding Files:
git add <filename> # Stage specific file
git add . # Stage all files
Committing Changes:
git commit -m "Commit message"
Creating a Branch:
git branch <branch-name>
git checkout <branch-name> # Switch to the new branch
Merging Branches:
git checkout main # Switch to main branch (or target branch)
git merge <branch-name> # Merge changes from <branch-name> into main
Linking to a Remote Repository:
git remote add origin <remote-url> # Add a remote repository
Pushing Changes:
git push -u origin main # Push local changes to the remote repository
Pulling Changes:
git pull origin main # Pull latest changes from remote repository
git add
and commit changes.git log # View commit history
git log --oneline # Compact view of commit history
Undoing Changes:
git reset HEAD <filename> # Unstage changes
git checkout -- <filename> # Discard changes in working directory
Git Help:
git --help # Git command help