git init
Initializes a new Git repository in your project directory. This sets up all necessary files and tracking to start version control.
git init
git add
Adds changes in your working directory to the staging area. You can specify individual files or use . to add all changes.
git add filename
git add .
git commit
Records the staged changes to the local repository with a message describing what was changed.
git commit -m "Your commit message"
git push
Uploads your local repository content to a remote repository like GitHub.
git push origin main
git status
Displays the state of the working directory and staging area. It shows which changes are staged, unstaged, or untracked.
git status
git log
Shows the commit history for the repository, including commit IDs, messages, authors, and timestamps.
git log
git branch
Lists all the branches in your repository. The * indicates the current branch.
git branch # List branches
git branch -M
Renames the current branch. Often used to rename master to main.
git branch -M main # Renames current branch to 'main'
git config user.name
Sets the username for Git commits. This is usually done globally.
git config --global user.name "Your Name"
git config user.email
Sets the email address for Git commits. This should match your GitHub/GitLab account.
git config --global user.email "you@example.com"
git remote add origin
Connects your local repository to a remote one. Replace with your actual repository URL.
git remote add origin https://github.com/username/repository.git