Hello, Tech Enthusiasts! π Lets Dive into GIT and GITHUB today...
What is Git? π€
Git is a powerful version control system (VCS) that helps you manage changes to your code over time (maintains versions for each change you make in your file). Imagine you're writing a novel. Each draft you save is a snapshot of your work at that moment. Git does the same for your code, allowing you to track changes, revert to previous versions, and collaborate with others to avoid any code confusions between different developers sitting all across the world.
What is Version Control? π
Version control is a system that records changes to a file or set of files over time so you can recall specific versions later in case of any problems. With version control, you can:
Track changes π΅οΈββοΈ (like who made the changes, when were they made, what was the change etc.)
Revert files back to a previous state βͺ (in case of any issues with the recent state of our file)
Compare changes over time π (to solve the issues)
Collaborate with others without overwriting each other's work π€
Version Control System vs. File System π
A file system is where you store files on your computer. A version control system (VCS) like Git adds a layer of tracking and managing changes to these files. Hereβs how they differ:
File System: Just stores files and no tracking is there thus if a file gets delete, there is no record and thus can never be recovered.
Version Control System: Tracks changes, maintains history, and supports collaboration. Thus, ensuring that it can be recovered if lost.
What is Git Bash? π₯οΈ
Git Bash is composed of two words namely GIT which has commands to perform specific git tasks and BASH which gives us interface to run these commands. So, it is a command-line interface that allows you to interact with Git. It's like the terminal on macOS/Linux or the Command Prompt on Windows, but with Git commands built-in. It helps you run Git commands to manage your repositories.
Git Workflow Basics π¦
Untracked, Staged, and Tracked Files π
Untracked Files: New files that Git doesn't know about yet.
Staged Files: Files marked to be included in the next commit.
Tracked Files: Files that Git is already keeping track of.
Essential Git Commands π οΈ
Initialize a Git Repository π
git init
Creates a new Git repository .git (used to store the git revision history) in your current directory.
Add Files to Staging Area β
git add <filename>
Adds a file to the staging area.
Commit Changes π
git commit -m "Your commit message"
Records the changes in the repository with a message. Here, message is important so that with each change who ever sees knows why or for what was that change done thus the message should be relevant as well.
Check the Status of Files π
git status
Shows the status of changes as number of files in a directory which are untracked, modified, or staged.
View Commit History π
git log
Displays the commit history.
Simplified Commit History π
git log --oneline
Shows a condensed version of the commit history.
Restore Files π οΈ
git restore --staged <filename>
Moves a file from staging area to untracked area.
Branching in Git π³
Branching allows you to create separate lines of development. Itβs like having different drafts of your novel, each exploring a different plotline.
Branching Commands πΏ
Create a New Branch π±
git branch <branch-name> OR git checkout -b <branchname>
Creates a new branch.
Switch Branches π
git checkout <branch-name>
Switches to the specified branch.
List Branches π
git branch
Lists all branches in your repository.
Switch to a Branch π
git switch <branch-name>
Another way to switch branches.
What is GitHub? π
GitHub is a cloud-based platform (GUI) that hosts Git repositories and provides tools for collaboration, code review, and project management, making it easier to work and collaborate with others.
Basic GitHub Commands π
Clone a Repository π
git clone <repository-url>
Copies a repository from GitHub to your local machine.
Push Changes π€
git push
Sends your committed changes to GitHub.
Pull Changes π₯
git pull
Fetches and integrates changes from GitHub to your local repository.
Difference Between Git and GitHub π
Git: A distributed version control system to manage code history. It is a command line interface (CLI).
GitHub: A hosting service for Git repositories with added features for collaboration and project management between teams. It is a graphic user interface (GUI).
Conclusion π
Having knowledge of Git and GitHub is very important for any technical person as in today's time most of the company's use these to improve their virtual workspace and increase collaboration among their teams. Happy learning! π