Working With Git
Important Commands
git init: Initialize a git repository,
git status: Check the status of any directory whether it's a git repo or not,
git add file_name: Add the given file in the staging area,
git add -A: Add all files changed files into the staging area,
git add --a: Add all files changed files into the staging area,
git restore --staged file_name: Unstage the given file,
git restore file_name: Make the given file unmodified and restore the changed data.
git commit -m "Commit Message": Commit all the staged files,
git commit -a -m "Commit Message": Commit all the tracked files by skipping the staging area,
git log: List all the previous commits,
git log -p: List all the previous commits with changes,
git log -p -n: List n number of previous commits with changes,
git log --stat: List all the previous commits with short info about changes,
git log --prety=oneline: List all the previous commits in one line,
git log --prety=short: List all the previous commits with short info about changes,
git log --since=n.days: List all the previous commits in the previous n days,
git log --since=n.weeks: List all the previous commits in the previous n weeks,
git log --since=n.months: List all the previous commits in the previous n months,
rm -rf .git: Remove the .git file (i.e. Now the directory will not be a git repo)
git clone repo_url: Clone the repository,
git clone repo_url repo_name: Clone the repository and give the new name to the repository,
git diff: Compare the staging area with the working directory,
git diff --staged: Compare the previous commit with the current stating area,
git rm file_name: Delete a file, and stage the change,
git mv file_name_1 file_name_2: Rename/Move the file, and stage the change,
git rm --cached file_name: Untrack the given file,
git checkout -- file_name:
git remote add remote_name remote_url: Add remote to your git repository
git remote:
git remote -v:
git config --global alias.st status
Branching
git checkout -b branch_name: Create a new branch and switch to that new branch.
git checkout branch_name: Switch to branch
git branch: List all the branches