Version control system - Git

Version control system - Git

Introduction to version control

A version control system is used to track changes made to a file (or files) and allows you to revert to any previous state. It is a commonly used tool in software projects although embracing version control is possible for any type of file on a computer.

If you are interested in graphics or web design and want to maintain every version of a graphic file or web site layout (which seems like a reasonable idea), then using a version control system is the right tool for the job. It allows you to:

The most widely distributed version control system is Git and the projects created within it are repositories. The popular site GitHub provides network hosting for Git repositories.


An interactive introduction to Git

To get started with Git take a look at the interactive tutorial available at learngitbranching. It describes the most important concepts, which are presented in an intuitive, graphical form.

๐Ÿ› ๐Ÿ”ฅ Task 1 ๐Ÿ› ๐Ÿ”ฅ.

Solve the first four tasks from the Main: Introduction Sequence from learngitbranching:

  1. Introduction to Git Commits
  2. Branching in Git
  3. Merging in Git
  4. Rebase Introduction

and the following seven from Push & Pull โ€“ Git Remotes:

  1. Clone Intro
  2. Remote Branches
  3. Git Fetchinโ€™
  4. Git Pullinโ€™
  5. Faking Teamwork
  6. Git Pushinโ€™
  7. Locked Main

Hands-on Git exercises

๐Ÿ› ๐Ÿ”ฅ Task 2 ๐Ÿ› ๐Ÿ”ฅ.

Create an account at GitHub. Try to use a reasonable username, as repositories are often a sort of portfolio for future employers. Decide to post the code you create to Git repositories today - over time, the use of version control will become a good habit and you will already have some history of โ€œcodingโ€.


๐Ÿ› ๐Ÿ”ฅ Task 3 ๐Ÿ› ๐Ÿ”ฅ

Create a new repository using GitHub with a name such as hello-git. Fill in the description field (e.g.ย Example repository for learning how to use git), indicate your desire to create a README file and select license for your project (e.g.ย MIT).


๐Ÿ› ๐Ÿ”ฅ Task 4 ๐Ÿ› ๐Ÿ”ฅ.

Open a command terminal and configure the Git settings for your user:

git config --global user.name "Git user name"
git config --global user.email "Git user's email address".

Print the saved settings using the command:

git config -l

๐Ÿ› ๐Ÿ”ฅ Task 5 ๐Ÿ› ๐Ÿ”ฅ.

Clone the created repository from github to your computer with the command git clone address.


๐Ÿ› ๐Ÿ”ฅ Task 6 ๐Ÿ› ๐Ÿ”ฅ.

Create any text file and upload it to your Git repository. Use the following commands in the following order:

Command Function
git status (Optional) Displays current status of the repository that was downloaded.
git add -A The git add command allows you to split the changes made into different commits, while the -A argument causes all changes to be included at once. Note that the interactive introduction you solved omitted this command (it assumed committing all changes at once).
git commit -m "Brief description of changes made" Adds the changes made to the repository history.
git push Causes the remote repository to be updated with local changes.

Pushing to the remote repository will request for a password. Here you need to use personal access token instead of github password. There is an instruction how to create a personal access token.

After pushing the changes, watch the effect on Github, take a look at the repository user interface.


๐Ÿ› ๐Ÿ”ฅ Task 7 ๐Ÿ› ๐Ÿ”ฅ.

Code containing information about the author, dependencies in the project, installation and running instructions is simpler to use. Such information is usually placed in the README.md file. The language we use to create such files is Markdown. Using syntax information try to edit the README.md file to achieve the result listed below. Use the browser-based editor at Github to do this.


๐Ÿ› ๐Ÿ”ฅ Task 8 ๐Ÿ› ๐Ÿ”ฅ

Call the cat command on the local README.md file to display its contents. Why doesnโ€™t the file contain the changes you made? Update the local version of the repository using the git pull command.


๐Ÿ› ๐Ÿ”ฅ Task 9 ๐Ÿ› ๐Ÿ”ฅ

The projects you will be involved in in the future will most likely be team-based. Many repositories are also open-source, meaning you can influence the code in them. In this task, we will propose a change to the teachersโ€™s repository:

  1. Open the indicated repository in a browser.
  2. Go to the Issues tab and add them in the following format:
username:
GitHubUsername

The teacher will add you as a co-developer of the project.

  1. Clone the repository to your computer. (git clone address_www).
  2. Create your own branch in the repository by naming it with your username. (git branch name_of_the_branch). Note: You can execute command 4 and 5 with one command by adding an argument (git checkout -b name_of_the_branch).
  3. Change the current branch to the newly created one (git checkout name_of_the_branch).
  4. Create a new directory (name it with your username), and in this directory create a text file (name it with your initials .txt) and paste the sample text into it (United we stand, divided we fall!). Create a commit including the changes.
  5. Push the branch to the server. (git push -u origin name_of_the_branch). The -u argument causes changes to the newly created local branch to be tracked against changes to the remote repository.
  6. Using the Github user interface, create a pull request of the created branch to the master branch.

๐Ÿ› ๐Ÿ”ฅ Homework ๐Ÿ› ๐Ÿ”ฅ

Find an answer to the question - what is the purpose of the .gitignore file?

Sources and additional resources: