Git as a Version Management System - bounswe/2021SpringGroup12 GitHub Wiki
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.
Git is a Distributed type of VCS and also the most popular VCS in today's world.
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
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.
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]
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
- 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 command --help
: Manual for the command.
-
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.
-
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.
-
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.
-
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.
-
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
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]
- Go to Git Installer for Windows and follow the commands.
- Go to Git Installer for Mac and follow the commands.
- If you have already installed Homebrew as a packet manager, you can type directly
brew install git
to install git.
- To install git, you can run the following command
sudo apt-get install git-all
- [1]https://blog.devmountain.com/git-vs-github-whats-the-difference/#:~:text=GitHubโฆ-,what%27s%20the%20difference%3F,help%20you%20better%20manage%20them.
- [2]https://www.geeksforgeeks.org/version-control-systems/#:~:text=A%20version%20control%20system%20is,what%20change%20has%20been%20made.
- [3]https://www.atlassian.com/git/glossary/terminology
- [4]https://www.gfsis.org/files/library/pdf/3.pdf
- [5]https://github.com/git-guides/install-git
- [6]https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control
- [7]https://git-scm.com/docs
src: https://pics.me.me/github-taking-a-picture-of-your-code-notch-retweeted-definitely-66390193.png