Introduction to Git and GitHub - Advancing towards Version Control Mastery!
Hello Developers, this onboarding documentation on Git & GitHub will guide you through the nitty-gritties of how we manage collaborating with each other here at our ChaiCode Cohort company. As a developer it is important for us to track the progress in our codes, at the same time keep a backup of all the changes performed by our fellow developers on a cloud-based platform. We use Git & GitHub to do the same, which also allows us to collaborate with each other remotely with ease.
This onboarding documentation will guide you on how to use Git & GitHub as well as the practices which will prevent conflicting scenarios among collaborators for efficient woking.
Great! Let us now dive deep into what Git & GitHub actually are -
GIT :-
Git is a VCS (Version Control System) for developers. It tracks the changes between the versions of code, allowing us to move forward and backward between them when required. Git is developed by Linus Torvalds (founder of LINUX) in the year 2005.
why it is used →
Git allows ‘branching’ .
It is compatible with all types of systems like MAC , WINDOWS, LINUX etc.
Works as a backup software on local machine.
Git gives each developer a local copy of the full development history.
It runs it’s own garbage collection programme when the changes are unused, thus saves memory in our local machines.
GITHUB :-
GitHub is a central developer platform to create, store, manage and share codes. GitHub uses Git to provide distributed version control.
why it is used →
GitHub can be used as a cloud-backup service for codes.
It allows us to store and manage codes.
GitHub allows us to collaborate remotely without conflicts.
Now that we know about the basics of Git & GitHub, let us see how to use them -
INSTALLING GIT :-
Git is available for WINDOWS as well as MAC & LINUX, all operating systems.
Install Git on WINDOWS :
To download Git, go to → https://git-scm.com/downloads (or, google “download Git” ) .
Click on the “Download for Windows” button.
After downloading, keep all the default settings or, modify as required and install the “.exe” file .
Check if Git is installed in your computer or not -
Open command prompt / git bash > type in : git -v (or, git - - version)
(if Git version is mentioned, then it is successfully installed in your local machine)
Install Git on LINUX :
To install Git on LINUX, open the terminal & type the following command based on distribution:
Ubuntu/Debian*→*
Copysudo apt-get install git
Fedora*→*
Copysudo dnf install git
Install Git on MAC OS:
For Git installation on MAC, open Terminal & install Git using Homebrew :
Copybrew install git
SETTING UP Git & GitHub :-
Configuering Git →
configure Git Username & Email so that your changes can be tracked.
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
Configuering GitHub →
- If yor are new to GitHub - click on the Sign Up button. If you are already an existing user - click on Sign In .
2. Enter all the details and press Continue
Verify next and Confirm your email address and you are good to go… 👍
CREATING A REPOSITORY :-
- In GitHub a repository is like a project folder. To create a new repository click on the green new button on the left sidebar or, click on the "plus (+)” icon on the top-right corner of the nav bar.
Add a repository name, select visibility, add readme.md file if required.
Our first repository is now created.
CLONING THE CHAICODE REPOSITORY :-
Clone the repository using Git:-
To clone the chaicode repository copy the code and run in the terminal.
git clone https://github.com/ChaiCode/example-repo.git
Clone a repository using GitHub:-
Clone the chaicode repository click on the green “Code” button > Download ZIP.
BASIC GIT COMMANDS :-
OKAY! We have successfully compleated setting up Git. Let’s now look into some basic Git commands that we frequently use-
GIT INIT → This command is used to initiate projects.
Example:
git init <project name>
GIT ADD → This command is used to add files for tracking.
Example:
git add <file name>
GIT COMMIT→ This command is used to save upto a particular point / create versions in coding.
Example:
git commit -m "message"
GIT STATUS→ This command is used to see the status.
Example:
git status
GIT LOG→ This command lists the commits.
Example:
git log
GIT PUSH→ This command is used to push/ upload code on GitHub.
Example:
git push origin <branch-name>
GIT PULL→ This command is used to pull code from GitHub.
git pull origin <branch-name>
BRANCHING WORKFLOWS :-
Git workflows are strategies or patterns that teams adopt to manage code collaboration and version control using Git. We at ChaiCode Cohort comany use three branching workflows eg. master, bugfix & feature.
PULL REQUESTS (PR) :-
A pull request is a proposal to merge a set of changes from one branch into another. In a pull request, collaborators can review and discuss the proposed set of changes before they integrate the changes into the main codebase.
Here’s how to create a pull request →
Push Branch to GitHub:
Click the Compare & Pull Request button.
Select where you want to merge the changes.
Select the feature branch.
Provide a proper PR title.
Provide PR Description about the changes you made.
Click on the Create Pull Request button.
Commit Message Rules:
Write meaningful commit messages.
Use the present tense ("Add feature" not "Added feature").
Capitalize the first letter.
Keep the message short (50 characters or less).
Use prefixes like
fix:
,feat:
,chore:
,docs:
for categorization.Example:
feat: Add tea selection feature fix: Resolve login issue for tea enthusiasts docs: Update README with chai varieties