DEV Community

Emmanuel Cobham
Emmanuel Cobham

Posted on

Getting familiar with Git/GitHub

what is git

What is Git?

Git is a distributed version control system, which means that a local clone of the project is a complete version control repository.

Working remotely or offline is made simple by these fully working local repositories. After committing their work locally, developers synchronize their copy of the repository with the server copy. In contrast to centralized version control, which requires clients to synchronize code with a server before producing new code versions, this paradigm.

What is Github?

GitHub offers a developer platform driven by AI for creating, scaling, and delivering safe applications. More than 100 million developers from all over the world come together on GitHub to create things and improve them, whether you're planning new features, resolving bugs, or working collaboratively on modifications.

The benefits of Git include the following:

  • Simultaneous development: Each person can work on their own branches at the same time and has their own local copy of the code. Since nearly all operations are local, Git functions offline.

  • Faster releases: Branches enable concurrent and adaptable development. You release the stable, excellent code from the main branch. Work in progress is kept in feature branches and, when finished, is merged into the main branch. It is simpler to manage stable code and issue updates more rapidly when the release branch and development in progress are kept apart.

  • Built-in integration: Because of its widespread use, Git is integrated into the majority of tools and products. Git support is integrated into all major IDEs, and many tools provide metrics, reporting features, work item tracking, continuous integration, continuous deployment, and automated testing. The daily workflow is made simpler by this integration.

  • Strong community support: Git is the de facto version control standard and is open-source. Teams have an abundance of tools and resources at their disposal. Compared to other version control systems, Git has a larger community, which makes it simple to receive assistance when needed.

  • Git works with any team: By promoting cooperation, enforcing rules, automating procedures, and enhancing work visibility and traceability, Git combined with a source code management tool boosts team productivity.
    For continuous integration and deployment, work item tracking, and version control, the team can choose several tools. Alternatively, customers can select a service that supports all of these tasks in one location, such as Azure DevOps or GitHub.

  • Pull requests: Before integrating code changes into the main branch, use pull requests to consult with the team. Pull request talks are crucial for guaranteeing code quality and enhancing team understanding.
    Developers can examine builds, check commits, browse file changes, comment, and vote to accept the code in a sophisticated pull request experience provided by platforms like as GitHub and Azure DevOps.

  • Branch policies: Teams can set up Azure DevOps and GitHub to ensure uniform procedures and workflows throughout the team. To guarantee that pull requests fulfill requirements prior to completion, they can establish branch policies. By prohibiting direct pushes, requiring reviewers, and guaranteeing clean builds, branch policies safeguard critical branches.

Install and set up Git

Git needs to be explicitly installed and configured because it isn't yet a default option on machines. Additionally, Git needs to be kept up to date, just like any other software. Updates enable access to new features, address issues, and guard against security flaws.

Installing and maintaining Git for the three primary platforms is covered in the sections that follow.

Install Git for Windows

Download and install: https://git-scm.com/downloads/win

Git can be accessed via PowerShell or the command prompt after installation. Unless there is a compelling reason to alter the defaults, it is advised that you choose them during installation.

Git for windows download

For Windows, Git does not update itself. Downloading the most recent installer version will upgrade Git for Windows while keeping all settings intact.

Install Git for macOS

Git is installed the first time you try to launch it from the Terminal with macOS 10.9 (Mavericks) and later. Although installing Git on a system is simple with this method, it doesn't provide you control over how frequently security patches or upgrades are applied.

It is advised that you install Git using https://brew.sh/ instead, and that you utilize Homebrew tools to maintain Git's updates. Installing and controlling open source development tools on a Mac via the command line is made easy with Homebrew.

Homebrew

To install the most recent version of Git on a Mac, install https://brew.sh/ and execute the following commands.

brew install git

To update the Git install, use Homebrew's upgrade option:

brew upgrade git

The official Git website also offers a graphical installer for Git on macOS: https://git-scm.com/downloads/mac

Git for mac

Install Git for Linux

Installing and updating Git requires using the native package management system of the Linux distribution. For instance, on Ubuntu:

sudo apt-get install git

Configure Git on Linux

Establish the email address and name before you begin working with Git. Git adds this information to modifications so that others can determine which authors are responsible for which changes.

git config --global user.name " "

git config --global user.email ""

name and email config

Run > git config --list to confirm your username and email

config list

10 Essential Git commands:

1) Git clone: To download pre-existing source code from a remote repository (such as Github, for instance), use the Git clone command. To put it another way, a Git clone essentially creates a computer copy of the most recent version of a project stored in a repository.

2) Git branch: In the git world, branches are crucial. Multiple developers can collaborate on the same project at the same time by using branches. The git branch command can be used to create, list, and remove branches.

  • git branch

3) Git checkout: One of the most used Git commands is this one as well. You must first switch to a branch in order to work there. Git checkout is primarily used when we want to swap between branches. It can also be used to check out commits and files.

  • git checkout

4) Git status: All of the information we need about the current branch is provided by the Git status command.

  • git status

5) Git add: Unless the configurations are changed, all changes made to a file during creation, modification, or deletion will take place locally and not be reflected in the subsequent commit.
To incorporate the modifications of a file or files into our next commit, we must utilize the git add command.

  • git add

In order to include everything at once:

  • git add -A

6) Git commit: Perhaps the most often used Git command is this one. We want to store our changes after we've reached a particular stage of development, perhaps following a particular task or problem.
Setting a checkpoint in the development process that you may return to later if necessary is what git commit is all about.

  • git commit -m "commit message"

7) Git push: Sending your modifications to the remote server should be your next step after submitting your changes. Your commits are uploaded to the remote repository via Git push.

  • git push

8) Git pull: To obtain updates from the remote repository, use the git pull command. Combining the commands git fetch and git merge, git pull instantly applies the most recent changes to your local repository (git merge) and retrieves updates from a remote repository (git fetch)

  • git pull

9) Git revert: We occasionally have to reverse the adjustments we've made. Depending on our needs, there are a number of ways to reverse our modifications, either locally or remotely. However, we must use these commands cautiously to prevent unintentional deletions.
Git revert provides a more secure method of undoing our commits.

  • git revert

10) Git merge: Merging the branch with the parent branch (dev or master) is the last step when you've finished developing your branch and everything is functioning as it should. The git merge command is used for this.

  • git merge

Illustrations and Instructions for Using GIT Commands

Git for windows download

  • Establish the email address and name before you begin working with Git. Git adds this information to modifications so that others can determine which authors are responsible for which changes.

git config --global user.name " "

git config --global user.email ""

name and email config

  • Run > git config --list to confirm your username and email

config list

  • Setting up your workspace is the next stage. We must create a directory in order to accomplish this. The CD command is used to enter the directory once it has been created

We will call the directory "cv" and create the directory with mkdir command

mkdir cv

  • The CD command is used to enter the directory once it has been created

cd cv

  • In order for GIT to understand our command, we must then change the directory to a local GIT REPO and initialize the previously constructed directory. The command git init is what we use

git init

  • Next, we use the touch command to create an empty document (text file). The command touch index.html is what we utilize.

touch

  • The text file must then be opened for editing. We use the VIM command for this.

vim

insert mode

  • In order to edit, we must be in INSERT mode, which is accessed by pressing the letter I on the keyboard.

insert

  • Next We copy our cv and go to ChatGPT. Paste the information in your cv in ChatGPT

cv

Then type "provide index.html resume with the information above"

index.html resume sample

  • Then copy the code provided by ChatGPT and paste it in your Git Bash

paste node

  • We press the Escape button to save the file.

escape

  • Then Press Shift and Column together
  • Then type wq

wq

-The Press enter

Enter

  • The next step is to clone our repository by logging into your GITHUB account, clicking the plus sign in the upper right corner, selecting "new repository,"

new repository

  • Type a name under "Repository name" on the following page. The name used here is "git103". Click on ADD A README FILE then proceed to create a repository.

git103

  • Then proceed to create a repository.

create a repository

  • Click on the top green option that displays code on the next page after successfully creating a REPO. We have to then copy the URL.

constructing a REPO

  • The next step is to execute the command git remote add origin to clone the REPO inside the Git bash.

clone the repo

  • Now type git-status

git-status

  • The next step is to use the following command to move the text file we created to the staging area: git add index.html

git add

  • Use git status to check and confirm the file has been added

confirm

  • The command git commit -m "commit message" is then used to let git take a snapshot and push to git hub; the m there stands for message.

m

  • Pushing that file to Git Hub is the next step. You will be prompted to sign into your Git hub account after using the command git push origin master

push

-To accept the pull request from git bash, navigate to the repository you created on Git hub (Click Compare & pull request)

Click Compare & pull request

Top comments (0)