Як підписатися на репозиторій на GitHub

2.1 Основи Git – Створення Git-репозиторія

Якщо ви бажаєте прочитати тільки один розділ, щоб почати працювати з Git, саме цей вам і потрібен. У цьому розділі розглядаються всі основні команди, які потрібні для переважної більшості завдань, що виникають під час роботи з Git. До кінця розділу, ви будете в змозі налаштувати й ініціалізувати репозиторій, починати і зупиняти відстеження файлів, а також готувати і вносити зміни. Ми також покажемо вам, як налаштувати Git ігнорувати певні файли чи шаблони файлів, як швидко і легко скасувати помилки, як переглядати історію своїх проектів або зміни між комітами, а також як відправляти та отримувати зміни з віддалених репозиторіїв.

Створення Git-репозиторія

Зазвичай Git репозиторій отримують одним з двох способів:

  1. Беруть локальну директорію, що наразі не під контролем версій, та перетворюють її на сховище Git, або
  2. Звідкілясь клонують існуючий Git репозиторій.

У будь-якому разі ви отримуєте на локальній машині готове до роботи Git сховище.

Ініціалізація репозиторія в існуючому каталозі

Якщо у вас вже є тека з проектом, що наразі не перебуває під контролем версії, і ви бажаєте почати використовувати з цим проектом Git, спочатку треба перейти до теки цього проекту. Якщо ви ніколи ще цього не робили, команда може трохи відрізнятися в залежності від вашої системи:

$ cd /home/user/my_project
$ cd /Users/user/my_project
$ cd /c/user/my_project

Це створить новий підкаталог .git , який містить всі необхідні файли вашого репозиторія — скелет Git-репозиторія. На цей момент, у вашому проекті ще нічого не відстежується. (Див Git зсередини для отримання додаткової інформації про файли, що містяться в каталозі .git , котрий ви щойно створили.)

Якщо ви бажаєте додати існуючі файли під версійний контроль (на відміну від порожнього каталогу), ймовірно, вам слід проіндексувати ці файли і зробити перший коміт. Ви можете це зробити за допомогою декількох команд git add , що визначають файли, за якими ви бажаєте слідкувати, після яких треба виконати git commit :

$ git add *.c $ git add LICENSE $ git commit -m 'Перша версія проекту'

Ми розповімо що саме роблять ці команди за хвильку. Наразі, у вас є Git репозиторій з декількома файлами та першим комітом.

Клонування існуючого репозиторія

Якщо ви бажаєте отримати копію існуючого Git репозиторія — наприклад, проекту, в якому ви хочете прийняти участь — вам потрібна команда git clone . Якщо ви знайомі з іншими СКВ, наприклад Subversion, ви помітите, що команда називається “clone” (клонувати), а не “checkout” (перевірити). Це важлива відмінність — замість отримання просто робочої копії, Git отримує повну копію майже всіх даних, що є у сервера. Кожна версія кожного файлу в історії проекту витягується автоматично, коли ви виконуєте git clone . Насправді, якщо щось станеться з диском вашого серверу, ви зазвичай можете використати майже будь-який з клонів на будь-якому клієнті щоб повернути сервер до стану на момент клонування (ви можете втратити деякі серверні хуки (hook), проте усі дані під контролем версій повернуться – дивіться Отримання Git на сервері задля детальнішої інформації).

Щоб клонувати репозиторій треба використати команду git clone . Наприклад, якщо ви бажаєте зробити клон бібліотеки Git libgit2 , ви можете це зробити так:

$ git clone https://github.com/libgit2/libgit2

Це створить директорію під назвою libgit2 , проведе ініціалізацію директорії .git , забере всі дані для репозиторія, та приведе директорію до стану останньої версії. Якщо ви зайдете до щойно створеної директорії libgit2 , ви побачите, що всі файли проекту на місці, готові для використання.

Якщо ви бажаєте зробити клон репозиторія в директорію з іншою назвою, ви можете передати її як другий параметр команди:

$ git clone https://github.com/libgit2/libgit2 mylibgit

Ця команда робить те саме, що й попередня, тільки цільова директорія називається mylibgit .

Git має декілька різних протоколів передачі даних, які ви можете використовувати. Попередній приклад використовує протокол https:// , проте ви також можете побачити git:// або user@server:шлях/до/репозиторія.git , що використовує SSH протокол. Отримання Git на сервері познайомить вас з усіма можливими варіантами доступу до Git репозиторія, які може мати сервер, та “за” та “проти” кожного.

What Is GitHub? A Beginner’s Introduction to GitHub

In this article, we’ll first explain those two principles. Then, we’ll dig into more about GitHub and how you can actually use GitHub to work with WordPress and/or Kinsta.

What Is Version Control?

Version control helps developers track and manage changes to a software project’s code. As a software project grows, version control becomes essential. Take WordPress…

At this point, WordPress is a pretty big project. If a core developer wanted to work on one specific part of the WordPress codebase, it wouldn’t be safe or efficient to have them directly edit the “official” source code.

Instead, version control lets developers safely work through branching and merging.

With branching, a developer duplicates part of the source code (called the repository). The developer can then safely make changes to that part of the code without affecting the rest of the project.

Then, once the developer gets his or her part of the code working properly, he or she can merge that code back into the main source code to make it official.

All of these changes are then tracked and can be reverted if need be.

What Is Git?

Git is a specific open-source version control system created by Linus Torvalds in 2005.

Specifically, Git is a distributed version control system, which means that the entire codebase and history is available on every developer’s computer, which allows for easy branching and merging.

According to a Stack Overflow developer survey, over 87% of developers use Git.

What Is GitHub?

GitHub is a for-profit company that offers a cloud-based Git repository hosting service. Essentially, it makes it a lot easier for individuals and teams to use Git for version control and collaboration.

GitHub’s interface is user-friendly enough so even novice coders can take advantage of Git. Without GitHub, using Git generally requires a bit more technical savvy and use of the command line.

GitHub is so user-friendly, though, that some people even use GitHub to manage other types of projects – like writing books.

Additionally, anyone can sign up and host a public code repository for free, which makes GitHub especially popular with open-source projects.

As a company, GitHub makes money by selling hosted private code repositories, as well as other business-focused plans that make it easier for organizations to manage team members and security. We utilize Github extensively at Kinsta to manage and develop internal projects.

The WordPress code at GitHub

From here, you can view the various branches that are being worked on, as well as when someone made a commit (this is kind of like “saving” a file). Depending on how a repository is set up, you also might be able to create your own branch and make your own commits there.

And once you made some changes, you could submit that code back to a branch by making a pull request. A pull request is basically asking the person in charge of the branch to include your code. And it also helps that person see exactly what you’ve changed in the code.

If you wanted to edit some or all of the WordPress source code on your own account on a more permanent basis, you could also fork it by clicking the Fork button (a fork is similar in concept to a branch, but a fork is more permanent):

An example of forking code

WordPress itself was originally a fork of b2/cafelog. If you want a bit more information on how you can use GitHub, GitHub’s Hello World guide offers a beginner-friendly tutorial for getting started.

How To Use Git And GitHub At Kinsta

Kinsta offers a Git client so that you can use SSH to pull down your own Git repository from GitHub (or other similar services).

If you’re interested in using Git or GitHub at Kinsta, please read this help article for full instructions.

Other Ways To Use Git And GitHub With WordPress

Many WordPress theme and plugin developers host their projects’ source code at GitHub. For example, you can view the Elementor page builder code, the Zerif Lite theme source code, and lots more.

But there are also WordPress plugins that help you use Git with WordPress more directly.

For example, VersionPress aims to bring the power of Git to regular WordPress actions, like updating a post or installing a plugin. VersionPress adds version control for both your WordPress database and files.

WP Pusher is another Git-based plugin that lets you deploy themes and plugins directly from GitHub to your WordPress site.

How To Get Started With GitHub

To get started with GitHub:

  • Sign up for a free GitHub account
  • Follow the GitHub Hello World guide to understand the most popular actions you’ll likely want to take
  • Read: WordPress Version Control (What It Is and Best Solutions)
  • Read: Git vs Github: What’s the Difference and How to Get Started with Both

Get all your applications, databases, and WordPress sites online and under one roof. Our feature-packed, high-performance cloud platform includes:

  • Easy setup and management in the MyKinsta dashboard
  • 24/7 expert support
  • The best Google Cloud Platform hardware and network, powered by Kubernetes for maximum scalability
  • An enterprise-level Cloudflare integration for speed and security
  • Global audience reach with up to 36 data centers and 260 PoPs worldwide

Get started with a free trial of our Application Hosting or Database Hosting. Explore our plans or talk to sales to find your best fit.

Related Post

Чим ви ріжете вінілову решітку?Чим ви ріжете вінілову решітку?

Циркулярна пила з вініловими полотнами це ваш найкращий вибір. В іншому випадку хороша пара ножів для паркану впорається зі своєю роботою. Використовуючи a Циркулярна пила: Установіть на циркулярну пилку лезо