GIT : Setup & Useful Commands


GIT : Setup/Configuration & Useful Commands
Git setup/Configuration :

1. ssh-keygen -t rsa -C "Email ID" : for key generator (.ssh folder)
# Generating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa or ~/.ssh/id_rsa): [Press enter]

Now you need to enter a passphrase.
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]

Which should give you something like this:
# Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/you/.ssh/
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db "Your Email Id"

Copy that Key and paste into (Go to bitbucket Setting -> Click on SSH Key -> Add New key)

2. ssh -T : for check key is proper or not

3. For name : git config --global "Name"

4. For email : git config --global "Email ID"

Direct Existing Repository Commit on Git

  • git init
  • git remote add origin
  • git commit -m “Initial commit with contributors git”
  • git push -u origin master

Pull/Push on Existing Repository on Git

1. git status
2. git add .
3. git status
4. git commit -m "Message"
5. git pull origin "Branch Name".
6. git add .
7. git commit -m “Merge code "message"
8. git push origin “branchname”

Commons Useful command of Git

git config –global “XXXXXXX”set username

git config –global “”set username

git init set username

git status

git add . Will add all files

git add filenameSingle file

git rm – -cached filenameWill remove that file

git commit -m messageSingle commit

git log display Git log

git log end move to view log end and with this shortcut Shift + zz

git diff before commit diff b/w any file

git diff –cached after commit diff

git log – – oneline

git commit -a -m “msg”

ssh-keygen -t rsa -C “” : for key generator (.ssh folder)

ssh -T for check key is proper or not

git remote add origin when we want to share git project on the server. that means server URL.

git branch list of branch

git branch Branch Name list of branch

git checkout Branch Name switch to another branch

git checkout -b Branch Name Will create a new branch and switch to created branch

git merge Branch Name Merge branch

git checkout hashcode

git reset –hard 5b0c8327813ff97628f53513ea84abee81a3f9fb

git revert 63f3e7e37420438c11e2460c40952f45c124b346 a2ec8091431341e5154e47c085252ba1d58cca02

git rm Remove particular file

git stash Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.