GIT- Basic Commands
GIT- Basic Commands
changes in code, collaborate with teams, and manage project history efficiently. It allows
multiple developers to work on the same codebase simultaneously without conflicts.
1. Repository (Repo) – A directory containing your project files and the entire history of
changes.
3. Branch – A parallel version of the project to work on new features without affecting
the main codebase.
Configuration
Initialize a Repository
git init
Clone a Repository
git reset --soft HEAD~1 # Undo last commit but keep changes
git reset --hard HEAD~1 # Undo last commit and discard changes
git revert <commit-id> # Create a new commit that undoes a previous one
Basic Commands
1. Check Git Version
git --version
If Git is installed, it will display something like:
git init
If you're inside a project folder and want to track changes with Git:
cd my_project
git init
git status
On branch main
No commits yet
Untracked files:
index.html
style.css
5. Commit Changes
git log
8. Switch to a Branch
git diff
git stash
// This saves changes without committing and resets your working directory.
git push --set-upstream origin main // links local branch to the remote branch.