Git and GitHub Docs: For Beginner

First Assignment of Web Dev Cohort-1 by Priyansu Dash


Introduction to Git

What ?

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Why ?

One of the biggest advantages of Git is its branching capabilities. Unlike centralized version control systems, Git branches are cheap and easy to merge. This facilitates the feature branch workflow popular with many Git users.

How ?

  1. Installation of Git:-

    • For Windows:

      • Download the installer from the official Git website (https://git-scm.com)

      • Run the downloaded .exe file

      • Follow the installation wizard, using default settings is recommended for beginners

For mac:

  • Install using Homebrew: Run brew install git in Terminal

  • Or install Xcode Command Line Tools which includes Git: Run xcode-select --install

For Linux:

  1. Git Terminology:-

TerminologyDescription
Repository(Repo)A directory where Git tracks files, their history, and changes. Can be local (on your computer) or remote (e.g., on GitHub).
CommitA snapshot of changes in the repository. It represents a point in the project’s history.
BranchA separate line of development. Allows you to work on features or fixes without affecting the main codebase.
Main (or Master)The default branch where stable code resides. Projects usually merge completed work into this branch.
Staging AreaA temporary area where changes are prepared (staged) before committing them.
Working DirectoryThe local directory on your computer where files are being worked on.
RemoteA version of the repository hosted on a server or platform like GitHub, GitLab, or Bitbucket.
HEADA pointer to the latest commit in the current branch.
MergeCombining changes from one branch into another, typically from a feature branch into the main branch.
ConflictA situation where changes in different branches or commits overlap, requiring manual resolution.
  1. Git commands:-

Git setup Commands:-

git --versionCheck the installed Git version.
git config --global user.name "Priyansu"Set the username for commits.
git config --global user.email "p@p.com"Set the email address for commits.
git config --listDisplay all the Git configuration settings.

Creating and Managing Repositories:-

git initInitialize a new local repository.
git clone <repo_url>Clone the remote repository to your local machine

Checking Repository Status

git statusShow the current state of the working directory and staging area.
git logDisplay the commit history.
git log --onelineShow a simplified, one-line commit history.

Adding and Committing Changes

git add <File_name>Stage a specific file for commit.
git add .Stage all changes in the current directory.
git commit -m "message"Commit staged changes with a message.

Branching and Merging

git branchList all branches in the repository.
git branch <branch_name>Create a new branch.
git checkout <branch_name>Switch to a specific branch.
git merge <branch_name>Merge the specified branch into the current branch.
git branch -d <branch_name>Delete the branch.

There are many more commands to learn, so learn them by doing.


Introduction to GitHub

What ?

GitHub is a cloud-based platform where you can store, share, and work together with others to write code.

Storing your code in a "repository" on GitHub allows you to:

  • Showcase or share your work.

  • Track and manage changes to your code over time.

  • Let others review your code, and make suggestions to improve it.

  • Collaborate on a shared project, without worrying that your changes will impact the work of your collaborators before you're ready to integrate them.

Collaborative working, one of GitHub’s fundamental features, is made possible by the open-source software, Git, upon which GitHub is built.

Why ?

It's not necessary to use GitHub; you can use GitLab, Bitbucket, and many others. However, GitHub is popular among developers because it offers a user-friendly platform for easily collaborating on code projects. It uses Git's version control system, allowing developers to track changes, share code, review contributions, and access a large community of open-source projects. Its social networking-like interface encourages collaboration and project management across teams.

How ?

Navigate to GitHub and sign up using your email.

Then select on Sign up Button and fill in the all necessary details

After successfully creating an account, you can use GitHub.

Thank you for spending time here.

Priyansu Dash