DEV Community

Cover image for AN INTRODUCTION TO BASIC GIT WORKFLOW
Jesse Kenson
Jesse Kenson

Posted on

AN INTRODUCTION TO BASIC GIT WORKFLOW

What is Git?

The textbook definition of Git is an open-source, distributed version control system.

Since this is a beginner-friendly article, I shall break this definition down further.

Open-source simply means anyone is allowed to freely use, modify, share and redistribute Git.

A distributed version control system means that the Git can be accessed from both the central server and the user's local machine.

for more info on DISTRIBUTED VERSION CONTROL SYSTEMS,CLICK HERE

In terms of functionality, Git allows developers to track changes in their source code, coordinate work on shared projects, and maintain a detailed history of every modification made over time.

Expectation...

By the end of this article, you should have a fair understanding of basic Git commands and their respective uses. You should also be able to apply the basic Git workflow which involves these 6 key commands: Status - Add - Commit - Push - Pull - Branch

Basic Git Workflow Commands

git workflow

Understanding Git as a workflow rather than isolated commands makes it far easier for a new user. Mastering the sequence gives you a strong foundation for working confidently with Git in real-world projects.

1.Initialize
The workflow begins by creating a git repository. At this point, Git is active but no files are being tracked yet.

    git init
  #Initializes a new Git repository.
Enter fullscreen mode Exit fullscreen mode

2.Download a project
Alternatively, you can download an existing project, in which case there is no need for initializing.

    git clone [URL]
  #Creates a local copy of a remote repository.
Enter fullscreen mode Exit fullscreen mode

3.Status
Once the repository is initialised or downloaded, the next step is to understand what Git sees- whether files are untracked, which files are modified and which files are ready to be commit.

    git status
  #Displays the state of the working directory and staging area.
Enter fullscreen mode Exit fullscreen mode

4.Add/Stage files to commit
Before saving changes/commiting, you must select what to include after creating and/or editing files.

    git add [file]
  #Stages a file for a commit.
Enter fullscreen mode Exit fullscreen mode

5.Save changes
Once files have been staged, they can be permanently recorded in Git History.

    git commit -m "message"
  #Saves changes with a descriptive message.
Enter fullscreen mode Exit fullscreen mode

6.Save to work Server
Local commits stay on your machine until you send them to a remote repository(Such as Github or GitLab).

    git push 
  #Sends local changes to a remote repository(Server).
Enter fullscreen mode Exit fullscreen mode

7.Get latest From Server
Retrieves changes that other people may update in a remote repository by syncing the pushed files.

    git pull
  #Fetches and integrates changes from a remote repository.
Enter fullscreen mode Exit fullscreen mode

8.Create and Switch to branch
Branches allow you to work on new features or experiments wihout affecting the main codebase.

    git branch 
  #Lists, creates, or deletes branches.
Enter fullscreen mode Exit fullscreen mode

9.Merge Branches

    git merge [branch-name]
  #Combines a branch into the current branch.
Enter fullscreen mode Exit fullscreen mode

10.See History
This command is used to visualise and understand the project. it can therefore be used at any point after commits exist.

    git log --online --graph 
  #See who changed what and when.
Enter fullscreen mode Exit fullscreen mode

{Fun Fact;Git was created by a guy called Linus Torvalds in 2005 to manage the development of the Linux kernel.}

Final thoughts on Git.

Git is a versatile and powerful tool that increases the efficiency of software development projects and simplifies remote collaborations. We’ve explained the fundamentals of how Git works and the most common Git commands you need to know before using it.

If you've made it this far...
go forth

Top comments (0)