- Clone a Repository:
git clone <repository-url> - Navigate to Directory:
cd <directory> - List Directory Contents:
ls - Check Git Status:
git status(useful for verification) - Add File to Staging Area:
git add <filename> - Commit Changes:
git commit -m "Your commit message here" - Push Changes:
git push
- View Remotes:
git remote -v - Add Remote Upstream:
git remote add upstream <repository-url> - Pull from Upstream Master:
git pull upstream master
- Create a Branch:
git branch <branch-name> - Switch to a Branch:
git checkout <branch-name>
-
System: Configuration for all users on the computer
- Location:
/etc/gitconfigorProgram Files\Git\etc\gitconfig - Command:
git config --system
- Location:
-
Global (User): Configuration for a specific user
- Location:
~/.gitconfigor$HOME/.gitconfig - Command:
git config --global
- Location:
-
Project (Local): Configuration for a specific repository
- Location:
<project>/.git/config - Command:
git config
- Location:
- Set Username:
git config --global user.name "Your Name" - Set Email:
git config --global user.email "your-email@example.com" - View Configurations:
git config --list - Edit Global Config:
git config --global --edit - Unset Configurations:
- Remove specific setting:
git config --global --unset <config-name> - Remove all values of a setting:
git config --global --unset-all <config-name>
- Remove specific setting:
- View Config File Content:
cat ~/.gitconfig - Edit Config in Windows:
nano ~/.gitconfigorvi ~/.gitconfig
- Enable Color UI:
git config --global color.ui true
- Windows:
git config --global core.autocrlf true - Mac OS:
git config --global core.autocrlf input
- Status Shortcut:
git config --global alias.s "status -s" - Log Shortcut:
git config --global alias.lg "log --oneline --all --graph --decorate"
- Initialize Repository:
git init <project-name> - Add Files with Pattern:
git add ab*(adds files starting with "ab") - Simple Log View:
git log --oneline --decorate- Press
qto exit log view
- Press
- Rename a File:
git mv oldname.html newname.html- Alternative:
mv oldname.css newname.css
- Alternative:
- Delete a File:
- Using Git:
git rm <filename> - Directly:
rm <filename>, then update Git
- Using Git:
- Exclude specific files or folders. Example:
!special.log(Don’t ignorespecial.log)
- Add & Commit in One Command:
git commit -am "message"- Note: This won’t work for untracked files
- Branch Management:
- Check branches:
git branch - Create a branch:
git branch <new-branch-name> - Switch branches:
git checkout <branch-name>
- Check branches:
- Clone: Use if you don’t plan to contribute back or are a collaborator.
- Fork: Required if you don’t know the repository owner and want to contribute back.
- Create and Write to a File:
echo "Your text here" >> README.md
This organized guide should help streamline your understanding and usage of Git and GitHub.