Skip to main content

Command Palette

Search for a command to run...

OnlyFan: Your Ultimate Onboarding Guide to Git and GitHub

Updated
5 min read
OnlyFan: Your Ultimate Onboarding Guide to Git and GitHub

Introduction

This documentation is designed to help you understand git and Github becuase in our OnlyFan we use git and Github to track our code file, facilitate collaboration and effcient teamwork. This guide will walk you through everything you need to know.

What is GIT?

Git is a version control system that allows developers to track changes in their code, collaborate with others, and manage projects efficiently.

Why Git used?

Think there is a coder, this coder writes daily 50-60 lines of code. Day by day, the lines of code increase, and after a few months, they hire a new developer. The codebase grows larger, and they need to manage their code files and collaborate with each other.

In this scenario Git comes in like a superpower It helps you track changes in your files, provides a backup of your code, makes collaboration efficient, and lets you do so much more.

Installation and Setup:

For Linux/Ubuntu

sudo apt install git -y

Verify installation with:

git --version

For MacOS

If you have already install Homebrew you can simply run this command if not you have first install HomeBrew that run this command:

brew install git

Verify installation with:

git --version

For windows

It is very easy to install just click install.

Verify installation with:

git --version

Configure Git After installation, configure Git with your name and email:

Just open your terminal and run this command to set your name and email

git config --global user.name "Your Name"

git config --global user.email "yourEmail@gmail.com"

To check if your name and email are set or not, you can run this command to verify.

// For Name
git config user.name

// For Email
git config user.email

Github

GitHub is a service. GitHub is a cloud-based platform where you can store and share your code, and collaborate with others. There are many tools like GitHub, but in our OnlyFan, we use GitHub for our work.

Create a GitHub Account

Sign Up or click this Text

Cloning the HelloWorld Repository:

  • First, go to the OnlyFan Repo.

  • Copy the highlighted link

  • Then, open your VS Code terminal or a regular terminal.

  • Write a command to clone the HELLOWORLD repo.

// The 'clone' keyword helps to clone the repository

git clone https://github.com/hiteshchoudhary/open-source-contribution.git

Basic Git Commands:

git init

Git doesn't know which folder to track by default. To start tracking the current folder, you can use the command git init.

git init

git add

git add stages changes for tracking by Git. For example, if you add a new file to your folder, Git doesn't track it by default. To make Git track that particular file, you use the git add command.

// to track particular folder
git add fileName

// to track all folder
git add .

git status

The git status command shows the current status of your repository. It displays which files are being tracked, which files are not being tracked.

git status

git commit

for example there is 4 file in your folder that contribute to a feature and you want to commit(when you play game there is a thing called checkpoint the same thing does commit ) along with message.

// -m stand for message
git commit -m "message"

git log

View the history of commits.

git log

git push

Upload changes to the remote repository.

git push

Commit Message Rules:

  • 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.

feat: Add live pay feature
fix: Resolve screen freeze issue
docs: Update README

Branching Workflow:

  • Use main branch for production-ready code.

  • Direct commit to main branch should be avoided.

  • Create a new branch for each feature and branch name should be clear and descriptive .

git branch feature/add-upvote
git checkout feature/add-upvote
  • For critical bug fixes, create a branch named:
git branch bugfix/add-upvote
git checkout bugfix/add-upvote
  • Once your feature complete and tested successfully then merge it back into the main branch.
git checkout main
git merge feature/add-upvote

Merge Conflicts :-

If you encounter a merge conflict, don't worry. Try to communicate with your colleague who pushed that code and discuss which one is good. If your code is better for the OnlyFan if not include their code.

Pull Requests (PR):

  • Go to the OnlyFan repo and Fork the repo.

  • Clone your fork repo.
git clone https://github.com/forkrepolink/open-source-contribution.git
  • Always ensure you are not working on main branch. Create your own branch for your task.

  • If you complete the task then push the code on your branch not the main branch always take care of that.

git push origin feature/add-upvote
  • Then, Go to Github and create a pull request.

  • Add a descriptive title and explanation of your changes.

  • Request reviews from team members

Tools we are using for Git and Github in OnlyFan :

  • gitignore

  • gitLense

  • source Control

  • gitHub Pull Requests