check version git --version
Like Name, Email, Default Editor & Line Ending
Different levels for setting - System, Global & Local.
git config --global user.name "Harsh Verma"git config --global user.email harshverm776@gmail.comgit config --global core.editor "code --wait"git config --global -eLine endings -
| Windows | macOS/Linux |
|---|---|
| \r\n | \n |
- For Windows
git config --global core.autocrlf true - For Linux
git config --global core.autocrlf inputUse -h or --help
git initAdditional cmds -
-
Make directory -
mkdir Moon -
Open directory -
cd Moon -
Open a file -
start .gitfor Windowsopen .gitfor Linux
-
Remove a file -
- rm -rf .git
-
Listing files -
- ls
- ls -a
For checking the state of repo and staging area
git status Additional cmds -
- Creating a new file
echo hello > file1.txt - Appending content
echo world >> file1.txt - Adding files to staging area -
git add file1.txt file2.txtgit add *.txtgit add .
- Adding short comment
git commit -m "Initial commit"- Adding short and long comment
git commitRarely used
git commit -a -m "Some message"or
git commit -am "Some message"WD : Working Directory
SA : Staging Area
Removing file from both WD & SA
git rm file2.txt Additional cmds -
- File only remove from WD -
rm file2.txt - Checking SA -
git ls-files
Changes reflected in both WD and SA
git mv file1.txt main.js Additional cmds -
-
Renaming file -
mv file1.txt main.js -
Adding to SA -
git add file1.txt main.js
We can add file names like logs/ *.class *.log bin/
echo logs/ > .gitignoreor
echo > .gitignoreRemoving a file only from SA -
git rm --cached bin/git rm --cached -r bin/git status -s- Staged changes
git diff --staged - Unstaged changes
git diffAdditional cmds -
- Open file in cmd -
cat file2.txt - Open file in cmd with numbers -
cat -n file2.txt
- Configuring VScode-
git config --global diff.tool vscode- Configuring launching -
git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"- Viewing unstaged changes -
git difftool- Viewing staged changes -
git difftool --staged- Full logs -
git log- Logs in single line -
git log --oneline- Reverse Order -
git log --oneline --reverse"space" for moving a head and "q" for quitting
- Using unique identifier -
git show 921a- Viewing Last commit -
git show HEAD - One step back -
git show HEAD~1- Viewing particular file -
git show HEAD~1:.gitignore- Listing all the files -
git ls-tree HEAD~1git restore --staged file1.txtgit restore .Additional cmds -
- Removing all untracked files -
git cleangit clean -fdgit restore --source=HEAD~1 file1.js- Videos -
- Websites -