How To - GIT

logo@2x.png Website: git-scm.com

GIT Documentation - git-scm.com/doc

Installing GIT

brew install git

Verify Installed GIT Version

git version

Getting Help

git help <verb>

Show Default Settings

git config --list --show-origin

Setup Your GIT Identity

git config --global user.name "Ashutosh Kumar Sinha"
git config --global user.email ak_sinha@gmail.com

Set Your Default Editor (VSCode)

git config --global core.editor "code --wait"

Set Your Default DIFF Tool (VSCode)

git config --global diff.tool vscode
git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"

Set Your Default Merge Tool (VSCode)

git config --global merge.tool vscode
git config --global mergetool.vscode.cmd "code --wait $MERGED"

Verify Your Settings

git config --list

Initializing a Repository in an Directory

mkdir -p my_dev_project
cd /Users/user/my_dev_project
git init

Set up a GitHub Account

Go to "Github.com" and click on "Sign up"

Screen Shot 2021-01-05 at 10.04.55 PM.png

Create a New Remote Repository in Github

Click on "+" on right top corner and select "New repository"

Screen Shot 2021-01-05 at 10.08.36 PM.png

Create a new repository by filling in the details

Screen Shot 2021-01-05 at 10.08.54 PM.png

Add the Remote Repository

Copy the URL from Github for the new repository created earlier by clicking on "Code" green button on right corner

Screen Shot 2021-01-05 at 10.14.14 PM.png

git remote add origin <URL>

Ignoring Files

touch .gitignore

Example:

  • Ignore all files in any directory named build

build/

  • Ignore doc/notes.txt

doc/*.txt

Create a readme.md

touch readme.md
echo "This is a readme.md file." > readme.md

Stage the readme.md

git add readme.md

Commit the readme.md

git commit -m "Initial Commit"

Checking the Status of Your Files

git status

Upload the Committed File to Github

git push origin master

Verify on Github Repository for the readme.md

Screen Shot 2021-01-05 at 10.16.04 PM.png

To See What You’ve Changed But Not Yet Staged

git diff

Viewing the Commit History

May need to use "q" to quit.

git log

or use below command if you want it in a custom format

git log --pretty=format:"%h - %an, %ar : %s"

Viewing the Changes

May need to use "q" to quit. You scroll thru using up and down arrow keys.

git log -p

Modifying Commit

touch info.txt
echo "Another change added" >> info.txt
git commit -m 'Created info.txt'

Add another change

git add info.txt

Modify the commit

git commit --amend

Did you find this article valuable?

Support Ashutosh Kumar Sinha by becoming a sponsor. Any amount is appreciated!