Git as a Version Management System - bounswe/2021SpringGroup12 GitHub Wiki

What is Version Control System?

Imagine dozens of developers are working on the same software product. How can we prevent problems when some of them want to modify the same piece or what happens if someone mistakenly ๐Ÿ˜– deletes the last modification โ“

Actually, the answers are hidden in Version Control Systems. ๐Ÿ˜Ž

In order to contribute to the product team members do a lot of modifications in the source code like removing, adding code pieces. With the help of VCS, these works will be prevented from conflicting. In a version control system, each member can access the older versions of the product and the corresponding codes and also the information like who what, and when made been made.

So what is Version Control doing in this Git research?

Git is a Distributed type of VCS and also the most popular VCS in today's world.

Then what is Distributed Version Control System?

DVCS is a VCS that can contain multiple repositories where the users can have their own repositories. In addition to Git, Mercurial is also one of the popular DVCS. The below picture shows how the system works in general:

src : https://media.geeksforgeeks.org/wp-content/uploads/20190624140226/distvcs.png

What Is Git?

src: https://webmaster.kitchen/wp-content/uploads/q7uy4yxekcljpr70p2xk.png

Git is a free distributed version control system for observing changes in a project throughout time. It's launched in 2005 by Linus Torvalds -- the mastermind behind Linux.

In a nutshell, git is a system that records changes to our files over time and lets us recall previous versions of those files, in addition to letting us work with other people and facilitating collaboration.

Git vs Github?

src: https://serkankaya.net/wp-content/uploads/2019/02/git-github.png

"Github is a hosting service that lets you manage git repositories. Github is designed to help you manage projects that use git".[1]

Why git?

To illustrate, think it that way: You are a game developer and deployed your first game, congrats!

  • Reverting changes: After a while, you wanted to change the background music. That's simple, change the music and re-deploy. But if you regret this change and wanted to revert, this process is cumbersome if you are not using git. With git, you can revert with a few line of shell commands.
  • Storing old versions: You may think like "I can copy the old version on my disk", you are right to some extent. But think that your game takes up 1Gb on your disk. At each update you make you take a copy, after a while your disk will fill up. At this point, git comes to the rescue, again. It is super-efficient, takes minimal space.
  • Collaborative: Now that your first game was a real success, you aim high! You need to work with other people like huge companies do to make great games. How will you exchange codes and keep track of others' progress? Are you going to copy the code to a thumb drive like a cavemen? Of course not! You will use git to collaborate. Every person can download the codes and work on their machines, add some cool features and upload to the main.
  • Understand what has changed line by line: On the other hand, you can see the differences between each version of the project, this lets you observe the changes made easily

Terminology

  • Repository - A collection of commits, and branches and tags to identify commits.
  • Commit - This is a single point in git history which holds the information about the changeset.
  • Branch - A branch is an active area of development in Git. The most recent commit shows the tip of branch.
  • Master -It is the default development branch in git.
  • Head - A named reference to the commit at the tip of a branch.
  • Tag - A reference typically used to mark a particular point in the commit chain. In contrast to a head, a tag is not updated by the commit command.
  • Hash - A unique SHA1 code for every commit.
  • Fetch - Fetching means to get latest changes in branch and local/remote repos.
  • Merge - To bring out the content of another branch in the current branch.
  • Fork - By forking the repository you will be able to add commits and create Pull Requests.
  • Pull Request - Suggest some changes into the master branch.

Git Commands [7]

HELP

  • git command --help : Manual for the command.

Create Repo

  • git init <directory> : Create an empty Git repo in directory. If no arguments are given current directory is selected.
  • git clone <repo>: Download from an existing repo.

Check Repo

  • git status : List which files are staged, undstaged or untracked.
  • git diff : Show unstaged changes between index and working directory.
  • git log : Show all change history.

Branching

  • git branch : List all local branches.
  • git branch -av : List all local and remote branches.
  • git branch <new_branch> : Create a new branch named new_branch.
  • git checkout <branch> : Switch branch and update the working directory.
  • git merge <branch> : Merge the branch with current branch.

Make Changes

  • git add [file] : Stage the file and make it ready for commit.
  • git add . : Stage all changed files.
  • git stash : Saves the current changes and reverts to HEAD commit. Changes may be reached later.
  • git commit : Commit all staged files to versioned history.
  • git revert <commit-ish> : Revert the changes in the given commit and reverted state will be committed again.
  • git reset <file> : Unstages the files. But changes persists.
  • git reset --hard : Reverts everything to last commit.

Synchronization

  • git fetch : Get the latest changes from origin. (No merging)
  • git pull : Fetch the latest changes from origin and merge.
  • git push : Push local changes to origin.

src: https://miro.medium.com/max/880/0*cesFJY5JFpI0Rl4v.jpg

How to Install?

Installing git on different OS's are different. Generally, git comes installed by default in Linux and Mac machines. To check this you can open terminal and type: git version. If it gives the version that is OK, if not you should install git.[5]

Install on Windows:

Install on Mac:

Install on Mac from Homebrew:

  • If you have already installed Homebrew as a packet manager, you can type directly brew install git to install git.

Install on Ubuntu:

  • To install git, you can run the following command sudo apt-get install git-all

Additional Links

References

src: https://pics.me.me/github-taking-a-picture-of-your-code-notch-retweeted-definitely-66390193.png

โš ๏ธ **GitHub.com Fallback** โš ๏ธ