JavaRush/Courses/Python SELF EN/Basics of Working with Git

Basics of Working with Git

Open

9.0 A Little History

One of the key features of Git is branches, which allow parallel development of different features or versions of a program.

Originally, in Git DVCS, the default branch was called master. By default, every Git repository had a master branch. Developers rarely deleted it, as it played an important role in development.

In the summer of 2020, amidst protests and social unrest, the use of the terms master and slave in IT sparked heated discussions. In the search for a replacement for master, various alternatives were proposed, such as default and primary. However, the term main became the most popular in the end.

GitHub took steps and moved away from the term master when initializing a Git repository. Switching GitHub from master to main can be done in the account settings Repositories or by using the command:

$ git branch -m master main

In some educational materials, the term master might still be mentioned. You can learn more about transitioning to main via the following links:

9.1 What is Git and Why Do We Need It

Git is a powerful version control system used to track changes in source code during software development. It lets developers save different versions of files and coordinate teamwork on a shared project.

Key concepts of Git:

Repository

A repository (or "repo") is a place where the entire project history is stored, including all changes and file versions. In Git, the repository includes the working directory, the index (or stage), and the object database.

Commits

A commit (commit) is a saved state of the project. Each commit in Git contains info about what changes were made to the project, by whom, and when. Commits form the history of the project and allow you to roll back to any previous version.

Branches

A branch (branch) is an independent line of development. By default, Git creates a branch called main (formerly master). You can create new branches for developing new features or fixes and then merge them back into the main branch.

Merge and Rebase

Merge (merge) and rebase (rebase) are two ways of integrating changes from one branch into another. Merge combines the histories of two branches by creating a new commit, while rebase moves the commits of one branch on top of another, changing the commit history.

9.2 Main Git Commands

Here's a table with the main Git commands for version control:

Command Description
git init Initializes a new Git repository in the current directory.
git clone Clones a repository from a URL into a new directory.
git add Adds files to the staging area for the next commit.
git commit Commits the staged changes to the repository.
git push Sends changes from the local repository to the remote one.
git pull Updates the current branch with the latest changes from the remote repository.
git branch Shows, creates, or deletes branches.
git merge Merges changes from the specified branch into the current branch.
git rebase Applies changes on top of a new base (most commonly another branch).

These commands are the basic tools for working with Git, enabling you to manage code changes, branches, and merges in projects of any size. We'll dive deeper into them in future lectures.

9.3 Three Places Where Code Is Stored

When you're using a version control system for your code, your code, roughly speaking, will be stored in three places:

1. Remote Repository:

This is the centralized place where your code is stored, usually hosted on platforms like GitHub, GitLab, or Bitbucket. They provide centralized code storage and are the foundation for collaboration.

Remote repositories let developers share their changes, sync efforts, and maintain a project’s change history. Additionally, the remote repository acts as an integration point for automation processes like building, testing, and deploying apps.

2. Local Repository:

A local repository is your personal copy of the code stored on your computer. With this repository, you can perform all Git operations (commits, branching, merging) without needing an internet connection.

Local repositories let developers work isolated from their teammates, experiment, create new features, or fix bugs before the changes are merged and pushed to the remote repository.

3. Working Directory:

The working directory on your computer contains the current project files you’re actively working on. This is where you can view and modify files, add new functionality, or fix issues.

After making changes, you can add them to the staging area and then commit them to the local repository. The working directory is linked to the current branch in your repository, and switching branches changes the content of the working directory.

These components together provide a powerful infrastructure for managing source code, enabling developers to manage project history, collaborate, and share responsibility for the code.

9.4 GitHub - The Most Popular Free Repository

GitHub is the leading web-based platform for hosting source code, leveraging the Git version control system. Founded in 2008, it quickly became one of the most essential tools for developers worldwide.

GitHub lets users create repositories to manage projects, control and track code changes, collaborate with other developers, and work on projects either publicly or privately. It provides features like forks, branches, pull requests, and merges, making it easy for developers to work together on projects.

GitHub also includes functionality for issue tracking, feature requests, task management, and project wikis. The platform integrates with tons of tools and services, offering extensive capabilities for automating development, testing, and deploying applications.

GitHub supports a massive developer community that actively discusses programming best practices, project management, and much more. This makes it not just a project management tool but also a community hub where developers can share knowledge and experiences.

9.5 Registering on GitHub

Step 1. Go to https://github.com

Step 2. Sign up.

Step 3. Click on the New repository button to create a new repository.

Step 4. Set up the repository parameters:

  1. Repository name.
  2. Public or private. For starters, go with "Public".
  3. Add a README file – we’ll need it later.
  4. Click Create repository

Parameters we’re skipping for now:

  • .gitignore file. We’re skipping this for now. It’s handy for excluding specific files from your repository.
  • License. It defines how others can use and share your work.
  • Branch main. By default, GitHub uses main as the name for the main branch in your repository.

Step 5. Here’s our first repository

Installing Git on Your Computer

It's super simple: click on the first link on Google, install it, and you're good to go.

If you're using PyCharm, there's no need to install git separately. If PyCharm detects that Git isn't installed on your system, it'll suggest setting it up during the initial setup process.

Installation for Windows

As usual, you need to download the exe file and run it. Grab the Git installer from the official site: https://git-scm.com/downloads

Installation for Linux

Most of the time, git is already installed and available in Linux distributions. To check, open a terminal and type: git --version

Use your distribution's package manager to install Git. For example, on Ubuntu or Debian, you can use the following command:

sudo apt-get install git

Installation on macOS

Here too, first check if Git is already installed (see above for Linux).

If not, the easiest way is to download the latest version.

Комментарии
  • популярные
  • новые
  • старые
Для того, чтобы оставить комментарий Вы должны sign in
This page has no comments yet