Git - ashwin-shetty/Documents-Wiki GitHub Wiki

Content

Setup

Basic Command

Miscellaneous Commands

Git global setup

git config --global user.name "ashwin shetty"
git config --global user.email "[email protected]"
# Test
git config --list

Create a new repository

git clone https://github.com/ashwin-shetty/***.git
cd my-first-project
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder

cd existing_folder
git init
git remote add origin https://github.com/ashwin-shetty/***.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin https://github.com/ashwin-shetty/***.git
git push -u origin --all
git push -u origin --tags

List all branch

# To see local branches
git branch
# To see remote branches
git branch -r
# To see all local and remote branches
git branch -a

Checkout branch from remote

git checkout --track origin/release/v-1.0.0

Checkout and Switch to Local Branch

git checkout master

Delete Local Branch

git branch -d release/march-2021

Add multiple file

git add index.txt index2.txt index3.txt

Undo/Reset Git Add

-- all file
git reset 

-- single file
git reset index.html

Reset single file

git checkout HEAD -- index.txt

Change commit message

git commit --amend -m "New commit message."

Viewing unpushed Git commits

# Shows all unpushed commits 
git log origin/master..HEAD

# Shows all unpushed commits with differences.  
git diff origin/master..HEAD

Delete a file

git rm file1.txt
git commit -m "remove file1.txt"