git config --global user.name "My Name"
git config --global user.email [email protected]
git config --global core.editor "code --wait"
git config --global -e
git config --global init.defaultBranch main
#Windows -> \r\n (Carriage Return + Line Feed)
#Linux/Mac -> \n (Line Feed)
git config --global core.autocrlf input
#Set 'true' instead of 'input' on windows system
mkdir project
cd project
git init
echo hello > file1.txt
echo hello > file2.txt
git add file1.txt file2.txt OR git add *.txt OR git add .
git status
git commit -m "Initial Commit"
echo test >> file1.txt
git commit -am "Fix the bug"
git ls-files
rm file2.txt
git status
git ls-files
git add files2.txt
git commit -m "Remove unused code"
mv file1.txt main.js
git status
git add file1.txt main.js
git status
#All that in one command
git mv main.js file1.txt
git commit -m "Refactor code"
mkdir logs
echo testing logs/dev.log
echo logs/ > .gitignore
git add .gitignore
git commit -m "Add gitignore"
git ls-files
git rm -h
git rm --cached -r <file> #Remove files recursively from staging (index) area
git ls-files
git commit -m "Remove file that was accidently commited"
#Now you can add files/folders in .gitignore and it won't be uploaded from now on!
* Learn more what to add in .gitignore: https://github.com/github/gitignore
git log
git log --oneline
git log --oneline --reverse
git show 921a2 #using identifier from `git log --oneline`
(identifier's first few characters will work if it is unique)
git show HEAD~1 #Backtrack from HEAD pointer to specified number backwards
git show HEAD~1:bin/app.bin
#View content of the files in the previous commit
git show HEAD~1:.gitignore
git ls-tree HEAD~1
git restore --staged file1.js
OR
git restore --staged .
mkdir learning-git
cd learning-git
git init
git branch -M main
git remote add origin [email protected]:HiteshPaliya/learning-git.git
git pull -u origin main