Skip to content

Git Tutorial

Erdinç edited this page Feb 17, 2020 · 1 revision

What is Git? [1]

Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.

Why Do We Need Version Control System?

[2]Version control systems are a category of software tools that helps record changes to files by keeping a track of modifications done to the code. It helps developers to keep the track of the progress made on the project. For example, one can review the project history to find out:

  • Whether anything changed inside the project,
  • Who made these changes,
  • When these changes are made,
  • Why these changes are made.

[3]There are several types of version control systems, some of which are:

  • Local Version Control Systems
  • Centralized Version Control Systems
  • Distributed Version Control Systems

Git is a distributed version control system, and it is one of the most popular version control systems worldwide.

Distributed Version Control System Diagram

Why Git?

There are a few reasons that Git is one of the most popular version control systems, such as:

  • It is lightning fast
  • You can work offline on your local machine
  • You can undo your mistakes
  • Branching is easy and fast
  • It has a huge community.

Terminology [4]

Blame: Describes the last modification to each line of a file, which generally displays the revision, author and time. Good for tracking down the time of a feature added, or finding a bug.

Branch: Parallel version of a repository. Although it is contained within the repository, it doesn't affect the primary or master branch allowing one to work freely without disrupting the live version. When one has made the changes, they can merge the branch back into the master branch.

Clone: Local copy of a repository that lives on the computer instead of a server. One can edit the files in some editor and use Git to keep track of the changes without being online. However, it is connected to remote version so that changes can be synced between the two versions. One then can push the changes when one is online to keep remote and local repository synced.

Commit: Also called "revision", is an individual change to a file. Everytime you save a file, it creates a unique ID that allows you to keep record of what changes were made, when, by who and why. Commits usually contain a commit message which briefly describes what changes were made.

Collaborator: A person with read and write access to a repository who has been invited to contribute by the repository owner.

Contributor: Someone who contributes to the project.

Dashboard: Personal dashboard is the main hub of your activity where you can keep track of issues and pull requests you are following or working on, navigate through repositories and team pages, and learn about recent activity in repositories you're watching or participating in.

Diff: The difference in changes between two commits, or saved changes. The diff will visually describe what was added or removed from a file since its last commit.

Fetch: Fetching refers to getting the latest changes from an online repository without merging them in. After fetching, one can compare them to their local branches (the code residing on the local machine).

Fork: Personal copy of another user's repository that lives on your account. Allows you to freely make changes to a project without affecting the original. Forks remain attached to the original, allowing you to submit a pull request to the original's author to update with your changes.

HEAD: You can think of the HEAD as the "current branch". Issue: Issues are suggested improvements, tasks or questions related to the repository. Issues can be created by anyone (for public repositories), and are moderated by repository collaborators. Issues contain their own discussion forum, and can be labeled and assigned to a user.

Merge: Merging takes the changes from one branches (in the same repository or from a fork), and applies them into another. This often happens as a pull request (which can be thought of as a request to merge, made from GitHub web interface for instance), or via the command line.

Pull: Refers to when you are fetching in changes and merging them. For instance, if someone has edited the remote file you're both working on, you'll want to pull in those changes to your local copy so that it's up to date.

Pull Request: Pull requests are proposed changes to a repository submitted by a user and accepted or rejected by a repository's collaborators. Like issues, pull requests each have their own discussion forum.

Push: Pushing refers to sending you committed changes to a remote repository, such as a repository hosted on GitHub.

Repository: A repository(also called repo) is the most basic element of GitHub. They're easiest to imagine as a project's folder. A repo contains all of the project files (including documentation), and stores each file's revision history. Repositories can have multiple collaborators and can be either public or private.

Stage: Making a change in the project not committing them.

Status: Type of status check on Github.

Status Checks: Status checks are external processes, such as continuous integration builds, which run for each commit you make in a repository.

Watch: Lets you "watch" a project, meaning that you will be notified when a change is made on the project.

Essential Git Commands [5]

  • git config --global user.name "<fullname_you_want_to_use>: Sets the user name for you to use Git. It is used in commits.
  • git config --global user.email"<email_you_want_to_use>: Sets the email for you to use Git. It is used in commits.
  • git init [name]: Initialize a git repo for a new or existing project. Use it in the root of your project directory.
  • git clone [url_of_clone]: Copy a repository from remote source, also sets the remote to original source so that you can pull again.
  • git status: Lists out all the files that have been changed in your working directory.
  • git add [filename]: Adds the file(if given as arg) or all changes to stage/index in your working directory. Also can be used with flags "-all", "-p" (allows you to stage parts of a changed file, instead of the entire file. Good for a readable history.)
  • git commit -m "[commit_message]": Commits your changes and sets it to new commit object for your remote with the message you wrote.
  • git push: If you have added and committed your changes, this helps you to push to remote.
  • git pull: Gets the changes from remote repo and updates the local repo.
  • git branch: List out all the branches. Add "-a" flag to list all the remote branches as well.
  • git checkout [branch_name]: Switch to different branches. Add "-b" flag before the branch name if you want to create and switch to a new branch.
  • git stash: Save changes that you don't want to commit immediately.
  • git merge [branch_you_want_to_merge]: Merge current branch with the branch you want to merge in. git rebase [branch] can also be used instead of merge if a more clean history is preferred, if used carefully.
  • git reset [mode] [commit]: Reset current HEAD to the specified state.

TODO: learn more about its usage.

  • git remote: To check what remote/source you have. To add a new remote, use git remote add [remote_url].
  • git diff: Shows the differences between the last commit and the current.

Summary of Version Control

References

  1. https://en.wikipedia.org/wiki/Git
  2. https://www.geeksforgeeks.org/version-control-systems/
  3. https://www.geeksforgeeks.org/version-control-systems/
  4. https://help.github.com/en/github/getting-started-with-github/github-glossary
  5. https://dev.to/dhruv/essential-git-commands-every-developer-should-know-2fl

🏠 Home

💻 The Project


👥 Group Members

--- Former ---


📜 Manuals


📜 Milestone Reports


🔬 Research


📜 Meeting Notes

--- CMPE 451 ---

Group Meetings

Backend Meetings

Frontend Meetings

Android Meetings

--- CMPE 352 ---


Clone this wiki locally