Git Tutorial - SeoulSKY/safe-zone-system GitHub Wiki

Git Overview

This summary only covers the basics needed for our project.

I recommend you check out this awesome cheat sheet here: GitKraken Cheat Sheet

Getting started with git

  • Git is a version control system, which means that it records committed changes to a file or directory so that you can recall specific versions later. It also helps developers to work on the same codebase in a coordinated fashion.

Setting up

Git Credential

Before starting work on the project be sure to set up your git credentials

Run in the command line(replace Your Name with your name and Your Email with your email )

git config --global user.name "Your Name"
git config --global user.email "Your Email"

Git Repository

  • A git repository is technically the .git/ folder inside a project. It tracks all the changes made to files in your project, building a history over time. This means that if you delete the .git folder, then you delete your project history and you no longer have a repository.
  • It is quite popular to refer to the directory/project which contains the .git/ folder as a repository as well. It is referred to as a repository precisely because it contains the .git/ folder.

How to obtain a git repo:

  • Create:
    • Create a directory for your project files
    • Within that directory, enter git init via command line
    • To view your repository’s .git/ folder, enter ls -la
  • Clone:
  • git clone is used to clone or copy an existing repository in a new directory. The original repository can be located on the local file system or on a remote machine.
  • To clone an existing repository:
    • Go to local repo via command line, enter:
    • git clone
  • For more information on git clone visit: Atlassian - git clone

Git Branches:

Git syncing commands:

  1. git remote
  • This command lets you create, view, and delete connections to other re. After cloning a repository, you must create a connection to it before you can interact with it in any meaningful way.
  • git remote add
    • This is used to connect your local repository to another repository, typically, the remote repository. To connect to another repo, enter git remote add
    • The name for a remote repository is called typically called origin. I.e. git remote add origin https:/github.com//.git
    • When you clone a repository with git clone, it automatically creates a remote connection called origin pointing back to the cloned repository. This can be renamed.
  • git remote rm used to remove a connection.
  1. git add
  • git tracks all events. It tracks new, modified, and deleted files and folders within your project. It does not automatically track files though. You must tell it what to track.
  • To add/stage a file to the git’s tracking list, enter git add . To add all files, enter git * or git add --all.
  1. git commit
  • git commit captures a snapshot of the project’s currently staged changes. You must commit your changes with a concise message.
  • To commit, enter git commit -m “”. If you forget to enter a message, you’ll be prompted by the command line to enter one.
  1. git push
  • git push pushes your committed changes to a specified branch in your remote repository. *To push, enter git push [remote name] . Remote name is not necessary.
  1. git stash
  • git stash temporarily stashes changes you’ve made to your working copy so that you can work on something else, and then later reapply changes in the stash to your working copy.
  1. git pull
  • git pull is used to download and merge content from the remote repository to your working copy.
  • It is essential that you have the latest code changes in your working copy. By pulling, you’re keeping your local repository in sync with the remote repository. git pull is a combination of git fetch and git merge.
  • To pull, enter git pull and it will pull
  • For more information on git remote, fetch, push and pull, visit: Atlassian - git syncing
  1. git merge
  • git merge is used to combine changes from one branch to another, such as merge changes from your branch to master.
  • Please check out this page on git merge: Atlassian - git merge

Pull Requests

Project Git Workflow

Commit Messages:

  • Commit messages would have a header and a body.

Header

  • The header has a special format that includes a type, and subject.
  • Example: Feat: create login page

Types

  • Feat: A new feature
  • Fix: A bug fix
  • Docs: Documentation only changes
  • Style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi colons, etc).
  • Refactor: A code change that neither fixes a bug nor adds a feature
  • Perf: A code changes that improves performance
  • Test: Adding missing tests.
  • Chore: Changes to the build process or tools and libraries

Subject

  • The subject is a concise description of the change
  • Use the imperative, present tense: change, not changed or changes
  • Don’t capitalize first letter
  • No dot (.) at the end

Body

  • (Recommended) Have the motivation for the change and contrast this with previous behaviour in present tense.
  • (Required) Have Closes at the bottom of the body so that the pull request is linked to the git issue.

Workflow Steps

  • We would have three kinds of branches:
    • The main branch
    • The feature branches
    • The release branches.
  • When assigned a task:
    • Create a branch off main
    • Create and name a feature branch with the format: -
    • Commit and push to your branch frequently, using the commit standard above.
    • When task is complete, locally runs tests and create a pull request to merge code to main or release branch.
  • We only directly merge to the release branch when fixing bugs found on the release branch, otherwise the feature branches are merged to main, and subsequently main is merged to release.
  • After every incremental deliverable presentation, the release branch will be merged to main to begin the next cycle of development.
⚠️ **GitHub.com Fallback** ⚠️