9.0 A Little History
Since its creation, the Git DVCS tool had a default branch called master
. Every Git repository had a master
branch unless the developer took explicit steps to remove it, which was rare because the master
branch plays an essential role in the software development world.
The use of terms master
and slave
in the computer industry caught everyone's attention in the summer of 2020 amidst numerous protests and growing social unrest. During the public discussion, several alternatives to master
emerged, including default
and primary
. However, the most popular term became main
.
GitHub took action and dropped the term master
when initializing a Git repository. Switching GitHub from master
to main
is possible in the account settings Repositories or by using the command:
$ git branch -m master main
In future lectures, the term master
is used. You can learn more about the transition at the following links:
9.1 What is Git and Why Do We Need It?
Git is a powerful version control system used for tracking changes in source code during software development. It allows developers to keep track of different file versions and coordinate work among multiple people on a single project.
Key concepts in Git:
Repository
A repository (or "repo") is a place where the entire history of a project is stored, including all changes and versions of files. In Git, a repository includes the working directory, the index (or staging area), and the object database.
Commits
A commit is a saved state of the project. Each commit in Git contains information about what changes were made to the project, by whom and when. Commits form the project history and allow you to revert to any previous version.
Branches
A branch is an independent line of development. By default, Git creates a main branch (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
Merging and rebasing are two ways to integrate changes from one branch into another. Merging combines the histories of two branches by creating a new commit, while rebasing moves commits from one branch on top of another, altering commit history.
9.2 Basic Git Commands
Here's a table of basic 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 index for the next commit. |
git commit | Records 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 version 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 onto a new base (most often, another branch). |
These commands represent essential tools for working with Git, allowing you to manage code changes, branches, and merges in projects of any size. We'll go into more detail on these in upcoming lectures.
9.3 Three Places for Storing Code
When using a version control system for your code, your code, roughly speaking, will be stored in three places:
1. Remote Repository:
This is a centralized place for storing your code, usually hosted on services like GitHub, GitLab, or Bitbucket. They provide centralized code storage and are the backbone for collaboration.
Remote repositories allow developers to share their changes, synchronize efforts, and maintain the project's change history. Additionally, a remote repository serves as the integration point for automation processes like building, testing, and deploying applications.
2. Local Repository:
A local repository is your personal copy of the code stored on your computer. In this repository, you can perform all Git operations (commits, branching, merging) without needing an internet connection.
Local repositories allow developers to work isolated from colleagues, experiment, create new features, or fix bugs before changes are merged and pushed to the remote repository.
3. Working Directory:
The working directory on your computer contains the current project files you are working on. It's where you can view and modify files, add new functionalities, or fix bugs.
After making changes, you can add them to the index (staging area) and then commit them in the local repository. The working directory is linked to the current branch in your repository, and changing branches alters the contents of the working directory.
These components together provide a robust infrastructure for managing source code, allowing developers to manage project history, collaborate, and share responsibility for code.
9.4 GitHub — The Most Popular Free Repository
GitHub is the largest web-based platform for hosting source code, using the Git version control system. Founded in 2008, it quickly became one of the key tools for developers worldwide.
GitHub allows users to create repositories for managing projects, control and track changes in code, collaborate with other developers, and develop in an open or private manner. It provides features like forks, branches, pull requests, and merges, making it easy for developers to collaborate on projects.
GitHub also includes issue tracking, feature requests, task management, and wikis for each project. The platform integrates with numerous tools and services, offering extensive possibilities for automating development, testing, and deploying applications.
GitHub supports a vast community of developers where best practices in programming, project management, and more are actively discussed. This makes it not just a tool for project management, but also a community hub where developers can share knowledge and experience.
9.5 Signing Up on GitHub
Step 1. Go to https://github.com
Step 2. Sign up…
Step 3. Click the "New" button to create a new repository.
Step 4. Specify the repository name and set its parameters.
Step 5. Add a README file to the project — we'll need it later.
Step 6. Click "Create repository".
GO TO FULL VERSION