Mastering Git Basics: A Guide for Beginners


๐ŸŸก git init
Creates a new local Git repository in your project directory. It sets up all the internal .git files needed to start tracking versions of your code.

Image description

๐ŸŸก git add
Adds specified file(s) to the staging area, telling Git you want to include them in the next commit. Example: git add filename.txt or git add . to stage everything.

Image description

๐ŸŸก git commit
Takes the staged files and permanently records their current state in the repository’s history. You must provide a message:
Example: git commit -m “Add new feature”

Image description

๐ŸŸก git status
Displays the state of your working directory and staging area โ€” shows which files are modified, staged, or untracked.

Image description

๐ŸŸก git log
Shows a list of all the commits made in the repository along with their hash IDs, authors, and commit messages.

Image description

๐ŸŸก git branch
Shows all local branches in your repo. The * indicates the current branch. You can also use it to create a new branch:
Example: git branch feature-1

Image description

๐ŸŸก git branch -M main
Renames your current branch (often master) to main. The -M flag forces the rename if the target name already exists.

Image description

๐ŸŸก git config –global user.name
Sets your name and email address globally so Git can attribute commits to you.

Image description

๐ŸŸก git config –global user.email
Sets your name and email address globally so Git can attribute commits to you.

Image description

๐ŸŸก git push
Sends your commits to a remote repository (like GitHub). Use -u for the first push to link your local branch with the remote one:user.email
Sets your name and email address globally so Git can attribute commits to you.

Image description



Source link