Skip to main content

Basic Git Workflow- how it's work

Basic Git Workflow:
  • Git is a software that allows you to keep track of changes made to a project over time. Git works by recording the changes you make to a project, storing those changes, then allowing you to reference them as needed.
  • Turning a directory into a project>> command: git init

The word init means initialize. The command sets up all the tools Git needs to begin tracking changes made to the project.

Output: would be like- Initalized an empty git repository in /home/ccuser/workspace/sorcerers-code/.git/

By the above output, we could say that The Git project was created.

  • Git workflow:

A Git project can be thought of as having three parts:
  1. 1. A Working Directory: where you'll be doing all the work: creating, editing, deleting and organizing files
  2. 2. A Staging Area: where you'll list changes you make to the working directory
  3. 3. A Repository: where Git permanently stores those changes as different versions of the project
The Git workflow consists of editing files in the working directory, adding files to the staging area, and saving changes to a Git repository.

  • Check status of changes in working dir>> Command: git status
In the output, notice the file in red under untracked files. Untracked means that Git sees the file but has not started tracking changes yet.
  • In order for git to start tracking, the file needs to be added to the staging area. We can add a file to the staging area with-
    Command: git add filename

    After adding file, check the status.
    Output:
    In the output, notice that Git indicates the changes to be committed with "new file: filename.fileformat" in green text. Here Git tells us the file was added to the staging area.
  • Check the differences of work between working directory and staging area:
Imagine that we type another line in our file. Since the file is tracked, we can check the differences between the working directory and the staging area with Command: git diff filename

Notice the output:
  • "Our first added change" is in the staging area, as indicated in white.
  • Changes to the file are marked with a + and are indicated in green.
    IMPORTANT: press q on your keyboard to exit diff mode.
  • After the above step, add the changes to the staging area in Git.
  • Committing changes:
    commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository.
    git commit is the command we'll do next. However, one more bit of code is needed for a commit: the option -m followed by a message. Here's an example:
    git commit -m "Complete first line of dialogue"
    Standard Conventions for Commit Messages:
    • 1. Must be in quotation marks
    • 2. Written in the present tense
    • 3. Should be brief (50 characters or less) when using -m
  • View log:
    Often with Git, you'll need to refer back an earlier version of a project. Commits are stored chronologically in the repository and can be viewed with:
    git log
    Instructions
    1.

    From the terminal, log a list of your commits.

    In the output, notice:

    • 1. A 40-character code, called a SHA, that uniquely identifies the commit. This appears in orange text.
    • 2. The commit author (you!)
    • 3. The date and time of the commit
    • 4. The commit message. 







Let's take a recap:

  • 1. Git is the industry-standard version control system for web developers
  • 2. Use Git commands to help keep track of changes made to a project:
    • git init creates a new Git repository
    • git status inspects the contents of the working directory and staging area
    • git add adds files from the working directory to the staging area
    • git diff shows the difference between the working directory and the staging area
    • git commit permanently stores file changes from the staging area in the repository
    • git log shows a list of all previous commits



Courtesy:
www.codecademy.com
MicrowaveSam (https://www.youtube.com/watch?v=73I5dRucCds)










Comments

Popular posts from this blog

Git Branching- Learn how to manage multiple versions of a project with Branching.

Git Branch: Up to this point, you've worked in a single Git branch called  master . Git allows us to create  branches  to experiment with versions of a project. Imagine you want to create version of a story with a happy ending. You can create a new branch and make the happy ending changes to that branch only. It will have no effect on the  master branch until you're ready to merge the happy ending to the master branch. In this lesson, we'll be using Git branching to develop multiple versions of a resumé. You can use the command below to answer the question: “which branch am I on?” Command : git branch Check what branch you are currently on.  In the output, the * (asterisk) is showing you what branch you’re on. The diagram above illustrates branching. 1. The circles are commits, and together form the Git project's commit history. 2. New Branch  is a different  version  of the Git project. It contains commits...

General Q&A related to Git and GitHub

Q1: What is the difference between Forking and Cloning on GitHub? Answer:  # When you say you are Forking a repository you are basically creating a copy of the repository under your GitHub ID. The main point to note here is that any changes made to the original repository will be reflected back to your forked repositories(you need to fetch and rebase). However, if you make any changes to your forked repository you will have to explicitly create a pull request to the original repository. If your pull request is approved by the administrator of the original repository, then your changes will be committed/merged with the existing original code-base. Until then, your changes will be reflected only in the copy you forked. In short: The Fork & Pull Model lets anyone fork an existing repository and push changes to their personal fork without requiring access be granted to the source repository. The changes must then be pulled into the source repository by the project maintaine...