GIT

  • Post author:
  • Post category:GIT

Check your fingerprint

ssh-keygen -l -E md5 -f ~/.ssh/id_rsa.pub

Create your GIT keys

If you are using multiple git accounts/repositories then it’s recommended to create different keys and associate them with your email ids. for exmaple

ssh-keygen -f "~/.ssh/id_rsa_github" -t rsa -b 4096 -C "name.gitlab@gmail.com"
ssh-keygen -f "~/.ssh/id_rsa_azuredevop" -t rsa -b 4096 -C "name.azdevops@gmail.com"
ssh-keygen -f "~/.ssh/id_rsa_awscode" -t rsa -b 4096 -C "name.awscode@gmail.com"

Mac Os

ssh-keygen -t rsa -b 4096 -C "emaild": "enter your filename" ex show below
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa): id_rsa_awscodecommit
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_awscodecommit.
Your public key has been saved in id_rsa_awscodecommit.pub.

add the keys as shown

ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_azuredevop
ssh-add ~/.ssh/id_rsa_awscode

ssh-add -l 
ssh-add -D                  //removes all ssh entries from the ssh-agent
ssh-add ~/.ssh/id_rsa        // Adds the relevant ssh key
Eror out //Could not add ssh keys
Eval `sssh-agent –s`.  
ssh-add ~/.ssh/id_rsa 

touch or create ~/.ssh/config and add these entries

Host github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_github

Host gitlab.com
  HostName gitlab.com
  IdentityFile ~/.ssh/id_rsa_azuredevop

Host bitbucket.org
  HostName bitbucket.org
  IdentityFile ~/.ssh/id_rsa_awscode

For Azure DevOps

Host ssh.dev.azure.com
IdentityFile ~/.ssh/id_rsa_mycompany
IdentitiesOnly yes

 Upload the pub eys to your repositories accounts

pbcopy < ~/.ssh/id_rsa.pub

GIT Config

git config --global user.name "user"     
git config --global user.email "user.name@gmail.com"

GIT Remote add & remove

git remote -v

git remote get-url origin

git remote show origin

git config --get remote.origin.url

git config --get remote.origin.url

git remote set-url origin git://new.url.here
git remote set-url origin

To push an empty commit

git commit --allow-empty -m "Trigger notification"
git commit --allow-empty

To Reinitialize ‘

The idea is to delete the .git/ and re-initialize. go to your cloned repo folder rm -rf .git,

re-initialize it, and then add your remote and do your first push.git init


git add .
git commit -m "your commit message"
git remote add origin
git push origin master

unstage or undo the local changes

To discard all local changes, but also to use them for next push

 git stash 

To discard local changes to a file permanently

Git checkout -- <file>

Git Branch

#git branch -a
* master
remotes/origin/master

The asterisk next to “master” in the first line of the output indicates that we are currently on that branch. The second line simply indicates that on our remote, named origin, there is a single branch, also called master.

To create a new branch, named user/feature, type the following

#git checkout -b user/feature 

To merge the changes from the develop branch to the master branch,

git merge user/feature  --no-ff

git push

Get Changes from remote //orgin/master

git checkout my_branch    # move on your branch (make sure it exists)

git fetch origin          # fetch all changes

git pull origin master    # pull changes from the origin remote, master branch and merge them into my_branch

git push origin my_branch # push my_branch

To push changes to your remote branch

git checkout -b user_freatre

Touch main.tf variables.tf terraform.tf

git add .

git push -u origin user_freatre

Ceate/touch .gitignore_global file

git config –global core.excludesfile ~/.gitignore_global

touch ~/.gitignore_global
vim .gitignore_global
git config --global core.excludesfile ~/.gitignore_global
Paste below content in that file

GIT IGNORE
#Terraform related files to ignore
*.tfstate
*.tfstate.*
*.tfvars
##Access key files##
id_rsa
## Ignore Mac OS Stuff
.DS_Store
.AppleDouble
.LSOverride
# Vscode file
.vscode
# Icon must end with two \r
Icon
# Thumbnails
._*
 
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
 
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
 
 
## Ignore Sublime text stuff
 
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
 
# workspace files are user-specific
*.sublime-workspace
# cache files for sublime text
       *.tmlanguage.cache
 
       *.tmPreferences.cache
 
       *.stTheme.cache
 
# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
*.sublime-project
 
# sftp configuration file
sftp-config.json
#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.pyc
*.pyc
*.xml
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad
#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
#Project files
[Bb]uild/
#Subversion files
.svn 
# Office Temp Files

This Post Has One Comment

  1. Anonymous

    Very good write-up. I absolutely appreciate this site. Thanks!

Comments are closed.