0% found this document useful (0 votes)
46 views

Git Workflow: Git Init Git Status Git Add Git Diff Git Commit

The document discusses the basic Git workflow which involves editing files in the working directory, adding files to the staging area, and saving changes to the Git repository with commits. It also introduces the three main parts of a Git project - the working directory, staging area, and repository.

Uploaded by

Achmad Rofiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Git Workflow: Git Init Git Status Git Add Git Diff Git Commit

The document discusses the basic Git workflow which involves editing files in the working directory, adding files to the staging area, and saving changes to the Git repository with commits. It also introduces the three main parts of a Git project - the working directory, staging area, and repository.

Uploaded by

Achmad Rofiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Git Workflow

Nice! We have a Git project. A Git project can be thought of as having three parts:
1. A Working Directory: where you'll be doing all the work: creating, editing, deleting and
organizing files
2. A Staging Area: where you'll list changes you make to the working directory
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. In Git, we save changes with a commit, which we
will learn more about in this lesson.

Generalizations
You have now been introduced to the fundamental Git workflow. You learned a lot! Let's take a
moment to generalize:
 Git is the industry-standard version control system for web developers
 Use Git commands to help keep track of changes made to a project:

o git init creates a new Git repository


o git status inspects the contents of the working directory and staging area
o git add adds files from the working directory to the staging area
o git diff shows the difference between the working directory and the staging area
o git commitpermanently stores file changes from the staging area in the repository
o git log shows a list of all previous commits

Generalizations
Congratulations! You've learned three different ways to backtrack in Git. You can use these
skills to undo changes made to your Git project.
Let's take a moment to review the new commands:
 git checkout HEAD filename: Discards changes in the working directory. Kembali ke
terakhir commit?
 git reset HEAD filename: Unstages file changes in the staging area.
 git reset commit_SHA: Resets to a previous commit in your commit history.

Additionally, you learned a way to add multiple files to the staging area with a single command:
git add filename_1 filename_2
branching overview
The diagram to the right illustrates branching.
 The circles are commits, and together form the Git project's commit history.
 New Branch is a different version of the Git project. It contains commits from Master but
also has commits that Master does not have

generalizations
Let's take a moment to review the main concepts and commands from the lesson before moving
on.
 Git branching allows users to experiment with different versions of a project by checking
out separate branches to work on.
The following commands are useful in the Git branch workflow.
 git branch: Lists all a Git project's branches.
 git branch branch_name: Creates a new branch.
 git checkout branch_name: Used to switch from one branch to another.
 git merge branch_name: Used to join file changes from one branch to another.
 git branch -d branch_name: Deletes the branch specified.

Git workflow
Now that you've merged origin/master into your local master branch, you're ready to
contribute some work of your own. The workflow for Git collaborations typically follows this
order:
1. Fetch and merge changes from the remote
2. Create a branch to work on a new project feature
3. Develop the feature on your branch and commit your work
4. Fetch and merge from the remote again (in case new commits were made while you were
working)
5. Push your branch up to the remote for review
Steps 1 and 4 are a safeguard against merge conflicts, which occur when two branches contain
file changes that cannot be merged with the git mergecommand. Step 5 involves git push, a
command you will learn in the next exercise

generalizations
Congratulations, you now know enough to start collaborating on Git projects! Let's review.
 A remote is a Git repository that lives outside your Git project folder. Remotes can live on
the web, on a shared network or even in a separate folder on your local computer.
 The Git Collaborative Workflow are steps that enable smooth project development when
multiple collaborators are working on the same Git project.
We also learned the following commands
 git clone: Creates a local copy of a remote.
 git remote -v: Lists a Git project's remotes.
 git fetch: Fetches work from the remote into the local copy.
 git merge origin/master: Merges origin/master into your local branch.
 git push origin <branch_name>: Pushes a local branch to the originremote.

Git projects are usually managed on Github, a website that hosts Git projects for millions of
users. With Github you can access your projects from anywhere in the world by using the basic
workflow you learned here.

You might also like