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 ?
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 TerminalOr install Xcode Command Line Tools which includes Git: Run
xcode-select --install
For Linux:
Ubuntu/Debian: Run
sudo apt-get in
stall git
Fedora: Run
sudo dnf install git
Git Terminology
:-
Terminology | Description |
Repository(Repo) | A directory where Git tracks files, their history, and changes. Can be local (on your computer) or remote (e.g., on GitHub). |
Commit | A snapshot of changes in the repository. It represents a point in the project’s history. |
Branch | A 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 Area | A temporary area where changes are prepared (staged) before committing them. |
Working Directory | The local directory on your computer where files are being worked on. |
Remote | A version of the repository hosted on a server or platform like GitHub, GitLab, or Bitbucket. |
HEAD | A pointer to the latest commit in the current branch. |
Merge | Combining changes from one branch into another, typically from a feature branch into the main branch. |
Conflict | A situation where changes in different branches or commits overlap, requiring manual resolution. |
Git commands:
-
Git setup Commands:-
git --version | Check 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 --list | Display all the Git configuration settings. |
Creating and Managing Repositories:-
git init | Initialize a new local repository. |
git clone <repo_url> | Clone the remote repository to your local machine |
Checking Repository Status
git status | Show the current state of the working directory and staging area. |
git log | Display the commit history. |
git log --oneline | Show 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 branch | List 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