Skip to content

Research on Git

Karahan Sarıtaş edited this page Aug 23, 2022 · 13 revisions

indir indir (1)

What is git? Git vs. Github? 🤔

Git is the most popular version control system in the world. A version control system records the changes we made to our code over time in a special database called a repository. With the help of this control version, we can look at our project history and see who has made what changes, easily communicate the changes in the project with our group members. We can easily revert our project back to an earlier state which makes our job way easier because otherwise, we would have to constantly store copies of the whole project in various locations, and tracking the contributions of other team members would be extremely difficult. Version control systems fall into two categories: Centralized and Distributed. Git is an example of a distributed version control system.

indir (2)

On the other hand, Github is a Git repository hosting service, which provides a web-based graphical interface and it helps every team member to work together on the project from anywhere and makes it easy for them to collaborate.

Git Project

  • There are three main components of a Git project:
    • Working tree (workspace)
    • Index (staging area)
    • Local repository
    • Remote repository
  • The HEAD in Git is the pointer to the current branch reference.
  • Git Merge Mechanisms:
    • Fast forward merge can be performed when there is a direct linear path from the base branch to the target branch, that is, if no new commits were made to the base branch since our branch was created, Git can do something called a “Fast Forward Merge”. This is the same as a Merge but does not create a merge commit.,,
    • Recursive merges are the default for any merges that aren’t fast-forward merges. These types of merges operate on two different heads using a three-way merge algorithm. The merge commit ends up having two parents once the merge is complete.

Git

Useful Git Commands

Setup

First, set up your environment to use Git.

  • git config --global user.name "[name]"”: Configure your Git user name.
  • git config --global user.email "[email]": Configure your Git email address you will be using.
  • git config --global color.ui auto: Set automatic command line coloring for Git for easy reviewing.

Init

Initialize your working directory.

  • git init: Initialize an existing directory as a Git repository.
  • git clone [url]: Retrieve an entire repository from a hosted location via URL.

Commit and Push

These are the most commonly used Git commands while working on a repository.

  • git status: Shows the status of changes as untracked, modified, or staged.
  • git add [file]: Add a file to commit.
  • git push: Push the committed files to the repository.
  • git pull: Fetch the updated content in the remote repository to your local environment.
  • git rm
    • git rm --cached [filename]: Removes the given file from the staging area. --cached flag makes this command remove the file only from the Git repository, but not from the filesystem.
    • git rm -r --cached [files]: Remove more than one file recursively.
  • git log
    • git log --oneline
    • git log --oneline --decorate --graph --all
  • git show [hash]: Displays detailed information about a commit with the given hash.
  • git restore
    • git restore --staged [filename]: Removes the file from the staging area, but leaves its actual modifications untouched.
    • git restore [filename]: Restore the file to its last state in Git by discarding the uncommitted local changes in it. If file is recently added, then this operation may delete the file.
  • git commit
    • git commit -m "message": Commit the staged files and add a message.
    • git commit -a -m "message": Commit staged and unstaged files (by staging them) and add a message.
    • git commit --amend -m "message": Changes the description of the most recent unpushed commit. Although content doesn't change, hash of the commit changes.
    • git commit -m "message" -- [path of the file]: Commit only a certain group of file(s) from the stage area. (Useful command I found out while working, can be used to improve the readability of commits)
  • git tag: See the current tags.
    • git tag [tag] [hash] -m "message": Tag the commit with the given hash and put a message.
    • git push [tag] origin: Push the tag to the remote repository. Tags can be observed on Github.

Branch & Merge

  • git branch
    • git branch: List local branches.
    • git branch -a: List all he branches.
    • git branch --remotes: List remote branches.
    • git branch [branch]: Add a new branch with the specified name.
    • git branch -d [branch]: Delete the given branch.
    • git checkout [branch]: Swap to another branch.
    • git merge [branch]: Merge the specified branch to the current branch we are working on.
  • git checkout [branch]: Change your currently active branch to the branch with the given name.
  • git stash: Let's say you have developed a new functionality for your project in the dev branch. However, you want to commit your recent contributions to another branch, you forgot to switch branches beforehand. In such a scenario, you can do the following in order to avoid dev from tracking the changes:
    git stash
    git checkout other-branch
    git stash pop
    
  • After merging a Pull Request, you can delete the branch in the remote repository (here in this repo). In order to delete it from local, you can follow these steps:
    • Delete the local branch using git branch -d <branch>. After this step, if you see that remotes/origin/branch still exists, then do the following:
    • Delete the remote branch that doesn't have any correspondence in remote repository: git fetch --prune
  • git branch -vv: Lists your local branches along with the remote branches they are tracking.

Useful Video Tutorials on Git and Github 📺

Miscellaneous 👾

References 🧾

Home 🏠

Project 💻

Practice Application 💻

Group Members 👨‍💻

Research 🔍

Timesheets 📝

CMPE451 Meeting Notes 🗒️

General Meetings

Frontend Meetings

Backend Meetings

Mobile Meetings

CMPE352 Meeting Notes 🗒️

Clone this wiki locally