Git

From DikapediaV2
Jump to: navigation, search

git - The stupid content tracker. Git is a stupid content tracker because it has no idea what's inside those blobs, and it doesn't try to store fine grained information like "lines 345-350 added, lines 502-508 removed" or anything like that.

https://github.com/git-guides

How to clone github repository to your local terminal


$ git clone https://github.com/ardikas/shell-scripts

How to set up your terminal with remote access to your Github repo


You may see this when you try to commit:

$ git commit
*** Please tell me who you are.  

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <ardika@DESKTOP-TOREEKS.localdomain>) not allowed

Do:

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


Another way to init Github repo:

git init
git config user.name "someone"
git config user.email "someone@someplace.com"

How to add SSH key and push using SSH


If you do git push and get this error, that is because password authentication was deprecated:

$ git push
Username for 'https://github.com': ardikas
Password for 'https://ardikas@github.com': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on 
currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/ardikas/python-scripts/'

Instead, my preferred way is to use SSH keys.

Follow these steps to generate an SSH key, add it to your Git Hub, and authenticate:

Then test the SSH key:

$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/<githubkey>

$ ssh -T git@github.com
Hi ardikas! You've successfully authenticated, but GitHub does not provide shell access.

Change directory into the local clone of your repository (if you're not already there) and run:

$ git remote set-url origin git@github.com:ardikas/python-scripts.git

Now try editing a file (try the README) and then do:

$ git add -A
$ git commit -m "memo"
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.28 KiB | 1.28 MiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:ardikas/python-scripts.git
 * [new branch]      main -> main


How to commit/upload to git


Note: For Ardika, follow the How to add SSH key and push using SSH steps above to commit and push via your mac/pc.

To commit:

git add [new file]
git commit -m "memo"
git push

If you get: git@github.com: Permission denied (publickey), follow the steps below...

Workaround (need to find permanent fix):

  • I put this as a script:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/<githubkey>
ssh -T git@github.com
  • Then run:
git remote set-url origin git@github.com:ardikas/terraform
git add * || git add [file]
git commit -m "memo"
git push

[+] Ardika's GitHub Repo



$ git config --list
user.email=<my email>
user.name=ardikas
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/ardikas/shell-scripts
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master



How to select branch using git


cd into the repo and run git checkout:

cd [repo directory]
git checkout [branch]

How to check which branch you are in:

git status