Git is the most popular source control system in modern software development. It is a powerful tool for version control and team collaboration at the source code level.
One of the main tasks for source control systems is to keep the source code and other project assets in a shared repository. The information there is available through the Internet or in a local environment. The team that works on the specific repository can clone, pull, commit, and push the local changes. If there are conflicting changes, they can fix and merge them in the end. If the developers have a problem with a specific commit, they can compare different versions of the same file and restore previous versions.
In our video, we work with Git and GitHub by showing a few examples. First, we clone the repository, edit a local file, commit the local changes, and then publish the commit. If you haven’t worked with Git, first you need to install it. You can download it from here. To skip the process of creating a repository, we will be working with a sample repository:
We start the system console (which is also called “terminal window” or “command prompt“). Then, we clone the sample repository to a local directory, using the “git clone” command.
git clone https://github.com/SoftUni/playground
That will create a local copy of the specified repository in the “playground” subdirectory in the current directory.
Now we modify а local file, for example, the file “README.md“. We can use a text editor of choice, such as “Notepad“. We can open the file with Notepad by typing the following command:
After you add a new line in the file, save it. Now we have a modified file on the local disk. The changes are only made on your local device. If we want to add the changes to the local repository, we type the following command on the command prompt:
git add . & git commit -m “Added something”
We now have a local repository that holds changes. They are still not sent to GitHub. To send the local commits to the remote repository at GitHub, we can execute the following command:
This command needs the current Git user to have permission to write on the remote repository. It may ask for your username and password for authentication. If you are not registered yet, you can do it from here.
After the command compiles successfully, we can open the repository from the GitHub website and see the changes. We can also review the commits history. GitHub stores all the commits and we will know if someone deletes our changes.
To sum it up, the source control system keeps the source code in a remote repository. We can clone, edit, commit and push to the origin repositories. The workflow allows different team members to work together on a shared source code.
- Source Control Systems
- Git and GitHub