DEV Community 👩‍💻👨‍💻

Cover image for Intro to Git and GitHub
samkb@420
samkb@420

Posted on

Intro to Git and GitHub

Git is Version Control System(VCS) for tracking changes in computer files
It entails the following:

  • Distributed Version Control
  • Coordinates work between Multiple developers (Collaboration)
  • Who made What changes and When
  • Revert back at anytime (rollback)

GitHub is a for-profit company that offers a cloud-based Git repository hosting service.

Concepts of GitHub

  • Keep track of code history
  • Take 'snapshots' of your files
  • You can visit any snapshot at anytime
  • Local & Remote repositories

Lets make our hands Dirty and get Started by installing and performing basic git commands

Installation

Click on the below link it will take you to git download page then choose your OS and continue with the installation process follow the Instruction
https://git-scm.com/downloads

Getting started

Love command-line let's Dive in.😎

Check Git version

$ git --version

git version 2.25.1

Enter fullscreen mode Exit fullscreen mode

Configuring git on Your machine

$ git config --global user.name 'yourusername'
$ git config --global user.email 'youremail@abc.com'

$ git config --list
Enter fullscreen mode Exit fullscreen mode

Need help?
git help <verb> or git <verb> --help
ie. git git help branch or git branch --help
Lets create a directory where we shall do git operation and navigate into the directory

$ mkdir Learning_git 
$ cd Learning_git

Enter fullscreen mode Exit fullscreen mode

that's pretty easy,

Initializing a Git Repository

$ git init 
Enter fullscreen mode Exit fullscreen mode

expected output
Initialized empty Git repository in /home/samkb420/MyHobby/Learning_git/.git/

Adding file(s) to index
let use the ls command to list file and folders.

$ ls -la
Enter fullscreen mode Exit fullscreen mode

output
total 12
drwxrwxr-x 3 samkb420 samkb420 4096 Aug 19 02:14 ./
drwxrwxr-x 52 samkb420 samkb420 4096 Aug 18 19:11 ../
drwxrwxr-x 7 samkb420 samkb420 4096 Aug 19 02:14 .git/

lets create a file.
we shall build a simple calculator in python don't worry if you don't know python its not that complex.
let's open our text editor for me am using vscode.

$ touch calc.py
$ code .
Enter fullscreen mode Exit fullscreen mode

let do simple add method in python

def add(a,b):

    return a + b
print(add(5,5))
Enter fullscreen mode Exit fullscreen mode

having done that let do the following

$ git add -A  
$ git commit -m "[First commit #0001 ]"
$ git status 
Enter fullscreen mode Exit fullscreen mode

output

On branch main
nothing to commit, working tree clean
Enter fullscreen mode Exit fullscreen mode

Now lets push the code in a remote repo in this case I Will use github.
continue into github and create a repo.
lets add the github remote url
i.e
git remote add origin https://github.com/BitgritCampus/Learn_Git_Github.git

$git remote add origin remote_github_url
Enter fullscreen mode Exit fullscreen mode

let now push to GitHub

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Now add you credentials username and PAT(personal access token)
Hurrryy !! Done

Next on Merging.

Top comments (1)

Collapse
 
kelvinhalx profile image
KelvinHalx

Great thanks for the great lessons.
Waiting for the merging article lots to learn.

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.