git init → Initializes a new Git repository.
git clone <repository_url> → Clones a repository from a remote source.
git status → Shows the current status of the working directory.
git add <file> → Stages a specific file.
git add. → Stages all changes in the current directory.
git commit -m "Commit message" → Commits staged changes with a message.
git commit --amend → Modifies the last commit.
git merge <branch_name> → Merges a branch into the current branch.
git rebase <branch_name> → Reapplies commits on top of another branch.
git reset --hard HEAD → Resets the working directory to the last commit by reverting local changes.
git reset --soft HEAD → Resets the working directory to the last commit keeping local changes.
git push origin <branch> → Pushes commits to a remote branch.
git pull origin <branch> → Fetches and merges changes from a remote branch.
git log → Shows commit history.
git log --oneline → Displays a simplified commit history.
git diff → Shows changes between working directory and last commit.
Use merge when working in a team and want to keep the full commit history.
Use squash when you want to keep the history clean by merging multiple commits into one.
Use rebase when you want a linear commit history without unnecessary merge commits. The commit will be appended back to when the branch was created, giving the feeling of having a chronological order of commits.
Comments
Post a Comment