Learning Git as a beginner web developer

Gregory Dehaney
3 min readJun 18, 2021

There are so many web technologies to learn as a beginner web developer whether you decide to become a Front End or Back End Web Developer. Regardless of the path taken, you will be doing individual projects or working as part of a team collaborating on different projects.

Imagine working on a project and making several changes but later realized that changes made three days ago, or three hundred lines of codes was the correct one. This situation would cause some degree of frustration. Imagine another scenario where you are working on a team project with other developers, working on the same codebase and trying to sort through errors found after syncing the collaborative effort. This is where a tool such as git would be valuable.

Git is a free and open source distributed version control system created by Linus Torvalds. Git tracks file changes giving you a peace of mind knowing that a record of what has been done was stored, and you have the option to revert to a specific version of the codebase or state if needed. When it comes to collaboration, git allows changes from multiple people to be merged into one source. Git being a distributed version control system, has a remote repository which is kept on a server and a local repository which can be stored on each developer’s computer. This means that a full copy of the code can be stored on all the developers’ computers.

How to get started with git?

In order to get started the git installer can be downloaded at http://git-scm.com/downloads. The platform is available to all major OS such as Windows, Mac and Linux.

On a windows machine also install Git Bash at gitforwindows.org. This is a Bash emulation that runs similar to git on a UNIX or Linux environment.

The first time git is run we have to specific certain configuration setting such as name, email, default editor and line ending. We can specify this configure settings at three levels: system, global and local.

· System -All users

· Global — All repositories of the current user

· Local — The current repository

Git Configuration

git config — global user.name “John Doe”

git config — global user.email jdoe@gmail.com

Set Visual Studio Code as default editor

git config — global core.editor “code — wait”

Initializing repository

Create a directory

Mkdir projectdev

Move into directory

Cd projectdev

Initialize repository git init

Adding files to staging area of git

This command is used to stage a single file

git add file1.html

This command is use to stage a multiple files

git add file1.html file2.html

This command is used to stage with a pattern

git add *.html

This command is used to stage current directory and all the content in directory

git add .

Committing the files in staging

Use to commit with a one line message

git commit -m “Your message”

Viewing the Status

git status

Skip the staging area

git commit -am “your message”

How to remove files

Remove files from working directory and staging area

git rm file1.html

Remove files from staging area only

git rm — cached file1.html

Renaming or Removing files

git mv file1.html file1.txt

The .gitignore command is used to exclude files from being tracked with. Files such as log files.

.gitignore

Branches

Creates a new branch

git branch

Switches to the specified branch and updates the working tree files

git checkout

Combines the specified branch’s history into the current branch.

git merge

git branch -d

Synchronize Changes

This command is used to download contents from a remote repository

git fetch

Integrate remote tracking branch into current local branch

git merge

Uploads all local branch commits to GitHub

git push

Updates your current local working branch with all new commits from the remote branch on GitHub

git pull

--

--