DEV Community

Mohit Wadhwa
Mohit Wadhwa

Posted on

Git-Github Basics

GIT. GIT. GIT

The layers are Physical. Github - Way of storing snapshots
Enter fullscreen mode Exit fullscreen mode

Download git into the local machine.
Search on Google "git SCM', download and install into the respective local machines

Choose .git and .sh extentions.
Create a new repository.
echo "# git" >> README.md

go to your project folder

git init
git status (tells which branch, which commits)
git add (from local file system to "Staging area") 
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:mohit3wadhwa/<repo name>.git
git push -u origin master
Enter fullscreen mode Exit fullscreen mode

Connecting GITHUB repo (remote) to the local staging area with HTTPS.
git remote add origin https://github.com:mohit3wadhwa/git.git

git push
Enter fullscreen mode Exit fullscreen mode

if above does not work (because of not having master branch at remote), use below:

git push --set-upstream origin master
Enter fullscreen mode Exit fullscreen mode

Github credentials will be populated. Enter them and its done!

Connecting GITHUB repo (remote) to the local staging area with SSH.
(SSH Setup / Password-less Github Authentication from the local machine)
Generate ssh key for the machine using "ssh-keygen" in terminal

Public key for Github and Private key for local machine

Copy public key (complete)
go to Github > profile > edit profile > ssh and GPG key > New SSH key
Give Title and paste key in there
Click Add SSH key. It's done!

Do the following only if Https way was setup earlier

git remote remove origin
git remote add origin git@github.com:mohit3wadhwa/git.git
Enter fullscreen mode Exit fullscreen mode

Pull code from GITHUB to local

git pull
Enter fullscreen mode Exit fullscreen mode

Push an existing repository from

git remote add origin git@github.com:mohit3wadhwa/git.git
git push -u origin master
Enter fullscreen mode Exit fullscreen mode

SSH Setup / Password-less Github Authentication from the local machine

git remote add origin git@github.com:mohit3wadhwa/git.git
git push -u origin master
Enter fullscreen mode Exit fullscreen mode

Top comments (0)