Git & GitHub

Git & GitHub

Day 09

Q1.What is Git and why is it important?

Git is a distributed version control system (DVCS) designed for efficiently managing changes in code or any set of files. It allows you to:

Track changes: Each time you make a modification, Git creates a snapshot, enabling you to revert to past versions effortlessly.

Work collaboratively: Multiple developers can work on the same project simultaneously, with Git seamlessly merging their changes.

Branch and merge: Create feature branches to experiment without affecting the main codebase, and merge them back once ready.

Maintain history: Trace every change with detailed commit messages, providing valuable insights into project evolution.

Q2.What is the difference between Main branch and Master branch?

Historically, master was the default main branch in Git.

In recent years, many projects (including GitHub) have transitioned to using main as the default, emphasizing inclusion and avoiding potential master-slave connotations.

Both main and master serve the same purpose: storing the project's core codebase.

The choice between them is largely a matter of convention and alignment with community norms.

Q3.What is the difference between Git and GitHub?

Git: It's a command-line tool or software you install locally on your system to manage version control for your project's files.

GitHub: It's a web-based hosting service for Git repositories. Think of it as a storage platform where you can store, manage, and collaborate on Git projects online.

Key differences:

Feature Git GitHub

Git Primary function Version control system.

Github primary Function is Hosting platform for Git repositories

Git Installation Local software.

Github Instalation Web-based service

Git Collaboration Limited (requires manual sharing)

GitHub Collaboration Facilitates code sharing and collaboration through features like pull requests and issue tracking

Git Features Core version control commands

GitHub FeatureAdditional features like pull requests, issue tracking, branching tools, social features, integrations

Git Cost Free and open-source

GitHub Free plan with limited features, paid plans for additional features and team collaboration

Q4.How do you create a new repository on GitHub?

Sign up or log in to GitHub.

Click on the "New repository" button.

Enter a name for your repository (e.g., your-username/your-project-name).

Optionally, add a description, choose a visibility level (public or private), and select other options if needed.

Click "Create repository".

Voila! You now have a new GitHub repository ready to hold your project files.

What is the difference between local & remote repository? How to connect local to remote?

Local repository: A copy of the Git repository stored on your local machine. Here, you make changes and track them with Git commands.

Remote repository: The primary repository hosted on GitHub or another remote server. This is where you push your local changes to share them with others or back up your work.

Connecting local and remote repositories:

Initialize a local Git repository in your project directory using git init.

Use git remote add origin <remote_repository_URL> to add the remote repository URL.

Push your local commits to the remote repository using git push origin <branch_name>.

Remember to replace <remote_repository_URL> with the actual URL of your GitHub repository (e.g., github.com/your-username/your-project-name...).