Git Commands


Git Commands

How to set config details

git config --global user.name "sagar_thokal"

git config --global user.email "[email protected]"
 

How to add, commit and push files


git status

git pull origin main

git add -a

git commit -m " add-comment-msg"

git push -u origin main
OR
git push -f origin main

git pull 

########################## FOR Initial upload on git #####################


echo "# ProjectName" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/USERNAME/ProjectName.git
git push -u origin main

############### Check committed files on git ##################
git log --stat --pretty=short --graph

############### Check last 2 committed files on git ##################
git log -2 --stat --pretty=short --graph

############### Clone Repo ##################
git clone <remove-url>

############### Clone branch Repo ##################
git clone -b <branchname> <remote-repo-url>

############### ###########################
Updates were rejected because the tip of your current branch is behind
############################################
git branch
git branch
git branch --set-upstream-to=origin/test1 test1
git branch --set-upstream-to=origin/main main
git pull
git status
git add *
yarn prettier
git status
git add *
git commit -am "fixed merge changes and prettified"
git push
git merge origin/main

############## Get Few Days Back version file Data####################
*** Get Log History***
git log

*** view commited file changes ***
git show <commit_id>

*** view commited files list ***
git show --pretty="" --name-only <commit_id>

*** view file in terminal ***
git show <commit_id>:package/backend/src/api/services.ts

############# When conflict occurs ###########
compare local branch and Merge branch code. and apply changes
39 git config --global user.email "[email protected]"
40 git config --global user.name "Sagar D. Thokal"
41 git merge origin/test1

ERROR ::::
Auto-merging package/backend/src/api/services.ts
CONFLICT (content): Merge conflict in package/backend/src/api/services.ts
Automatic merge failed; fix conflicts and then commit the result.

42 git status
43 git add .
44 git status
45 git commit -m "merge test1 changes"
46 git push -u origin sagar
######################################################

##################################################
GIT create New Branch and Upload on remote

git checkout -b BRANCH-NAME
git push --set-upstream origin BRANCH-NAME
################################################

#############################################
If you have added (git add .) but not yet committed, you can restore all files using:

( Removes files from the staging area (undoes git add).)

git restore --staged .
 

Resets the working directory (discards changes).

git restore .