-
At first, open "git besh" command prompt.
-
ssh-keygen -t ed25519 -C "[email protected]" [ then press Enter ]
- Enter passphrase (empty for no passphrase): [Type a passphrase] { you can skip it press Enter }
- Enter same passphrase again: [Type passphrase again] { you can skip it press Enter }
-
eval "$(ssh-agent -s)" [ then press Enter ]
-
ssh-add ~/.ssh/id_rsa [ then press Enter ]
-
cat ~/.ssh/id_rsa.pub [ then press Enter ]
-
Then copy the Key and paste it git-hub ssh-key add settings.
Download Git from below link
https://git-scm.com/download/win
To check Git version
git --version
To upgrade Git version
git update-git-for-windows
To set username and email in locally
git config user.name "your name"
git config user.email "your email"
To set username and email in globally
git config --global user.name "your name"
git config --global user.email "your email"
To see which Email and Username used
git config --list
Run the below command and it will create .git folder by default
git init
If you want to create a project folder and inside project folder you want to create .git folder then run this command.
git init "project_folder_name"
If you want to see the status files and folder then run
git status
If you want to take all the files and folder in staging area then run
git add .
If you want to take a particular files in staging area then run
git add file_name
Ex: git add test.py
You can also use directory wildcard and directory and subdirectory wildcard
git add *.file_extension
Ex: git add *.js
git add **/*.file_extension
Ex: git add **/*.js
If you want unstag from staged then run
git restore --staged "file_name"
or
git rm --cached fileName
Move the file to local repository from stagging area
git commit -m "Your message"
If you want to add and commit together then run
git commit -am "Commit message"
If all you want to do is undo the act of committing, leaving everything else intact, run
git reset --soft HEAD^
If we want to delete 'n' number of commit then run
git reset --soft HEAD-num
Ex: git reset --soft HEAD-3
If all you want to do is undo the act of committing, and also removing from the stagging area then run
git reset HEAD^
And if you actually want to completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit then run
git reset --hard HEAD^
If you want to go back a particular previous commit
git checkout commit_hash_id
or
git checkout HEAD-NUM
EX: git checkout HEAD-3 (that means I want to back in third number commit)
If you want to go back a particular previous commit and then If we want to back at the last commit then run
git checkout master or main
If you want to see all the commit that you have done till then run.
git log
If you want to see all the commit that you have done till in short way then run.
git log --oneline
If you want to see a particuler number of commit then run
git log -num
Ex: git log -3
Shows the differences between the current state of your files and the last commit.
If you want to see all the commit that you have done till then run.
git diff
For particular file
git diff file_name
If we want to see the new add data after (add .) command than run
git diff --staged [ Risk ]
If we want compare two commit than run
git diff hash_id_of_first_commit hash_id_of_second_commit
If we want to see the all changes under a commit than run
git show hash_id
if you want to delete .git folder then run
rm -rf .git
To delete or remove file thne run
rm -r file_name
To delete or remove folder thne run
rm -r folder_name
To create a branch
git branch branch_name
To see all the branch
git branch
To go one branch to another branch
git checkout branch_name
To create a branch and go that branch at once run
git checkout -b branch_name
To delete a branch run
git branch -D branch_name
If we want to see last commit for all the branchs than run
git branch -v
If we want to see list all remote branches
git branch -r
If we want to see list all local & remote branches
git branch -a
If we want to connect a branch with master branch or one branch to another branch than run
git merge brance_name
If we want to delete any branch from GitHub then run
git push origin --delete branch_name
or
git push origin --d branch_name
If you change anything on GitHub and you want to fetch those change in your local machine then run
git pull
or,
git pull origin master or main
If you want to clone any repository then copy the repository link and open terminal then run
git clone repository_link
If you want to give new name of the project that you are going to download in your local machine then run
git clone repository_link new_project_name
If you want to push any change or repository then run
git push origin branch_name
or
git push -u origin branch_name
If you want to push all branch then run
git push --all
If you want to see git remote link then run
git remote -v
In Git, you can use the --pretty=format option to specify the output format for various Git commands, such as git log or git show. This option allows you to customize the output and display the information in a specific format.
Here are a few commonly used placeholders that you can include in the format string:
%H: Commit hash (full SHA-1)
%h: Abbreviated commit hash
%an: Author name
%ae: Author email
%ad: Author date (format respects the --date option)
%s: Subject
git log --pretty=format:"%h - %an, %ad : %s"