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...

How to Backtrack- Learn different ways to undo changes made to a Git project and when to use them.

Head commit : In Git, the commit you are currently on is known as the  HEAD commit. In many cases, the most recently made commit is the HEAD  commit. To see the  HEAD  commit, enter: git show HEAD The output of this command will display everything the  git log command  displays for the  HEAD  commit, plus all the file changes that were committed. For example:  Enter the command to show the  HEAD   commit. Notice the output. The ghost's most recently added line is in green text. Git Checkout: What if you decide to change the ghost's line in the working directory, but then decide you wanted to discard that change? You  could  rewrite the line how it was originally, but what if you forgot the exact wording? The command git checkout HEAD filename will restore the file in your working directory to look exactly as it did when you last made a c...