Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 10, 2022 10:42 am GMT

Git Bash Beginner's Guide

Introduction

Working on a project that requires an emulation layer for the Git command line interface would require you to know your way around using Git Bash. In this article, I will be breaking down how to install Git Bash, some Git commands you should be familiar with and how to set up a local repository with Git.

TABLE OF CONTENTS

  1. What Git Bash is and how to utilize it
  2. Installing Git Bash
  3. Git Commands
  4. How to set up your local repository with Git
  5. Git Bash paste instructions
  6. Conclusion.

Image description

What is Git Bash ?

For Microsoft Windows environments, Git Bash is a program that offers an emulation layer for the Git command line interface. The abbreviation BASH stands for Bourne Again Shell. An operating system can be accessed by written commands using a shell and a terminal program. Popular default shells for Linux and macOS are bash. On a Windows operating system, Git Bash is a package that installs Bash together with a few standard bash utilities.

Installing Git Bash

STEP 1

Go to the official website to download the Git Bash setup: https://git-scm.com/

Image description
The following window will appear once the file has been downloaded

Image description

STEP 2

After downloading, run the installer.

STEP 3

Select the components you need to install, launch the.exe file, and follow the installer's instructions.

Image description

STEP 4

Let the installation process finish then right-click on any folder and choose the Git Bash Here option from the context menu, you may launch Git Bash (right-click menu).

Image description

Git Commands

  • pwd

To print the "current working directory," use the Bash command pwd. On a DOS (Windows console host) terminal, typing pwd is the equivalent of typing cd. The current Bash session is located in this folder or directory.

  • ls

To 'list' the contents of the active working directory, use the Bash command ls. On a Windows console host terminal, ls is the equivalent of DIR.
ls to list the contents of the current directory.

  • cd

The cd command in both Bash and Windows console host. Change Directory is referred to as cd. An added directory name is used when using cd. Cd changes the working directory of the terminal session to the directory specified by the passed directory argument.
cd test to navigate into the new directory. You wont see an output when you do this.

  • git config--global user.name

    This comment will set your name.

  • git config --global user.email

    This comment will set your email.

  • git init

    Create a new blank repository and initialize an exciting directory as a git repository.

  • git commit

    Changes are saved to the local repository.

  • git status

    Displays the status of the working directory and the staging area.

  • git remote

    Manage the set of remotes that you are tracking with your local repository.

  • git checkout

    Match your working directory with your last commit.

  • git log

    Shows the chronological commit history for your current active branch.

  • git pull

    Fetches and merges on the remote sever to your working directory.

  • git push

    Changes the master branch to your remote repository.

  • git merge

    Merges the specific branches history into the current branch.

  • git rm

    Remove your file from your working directory and git staging area.

  • git diff

    Shows changes between commits.

  • git touch

    Creates a blank file inside your folder.

  • git add -a

    Add all modified and deleted files only to the staging area.

  • git checkout -f

    Match all your working directory file with your last commit.

  • git log -p

    See any particular "one" or more than one commit.

  • git diff --staged

    Compare the staging area to the last commit.

  • git rm --cached

    Remove your file from the staging area.

  • git branch -b

    Create a new branch and to open that particular branch.

To Set Up Your Local Repository With Git

follow the steps below:

STEP 1

Make a GitHub repository.

Image description

STEP 2

Give your repository a good name and create the repository.

Image description

Note: You can choose to include information about your project in the README file that comes at the top of your git repository. It helps spread awareness of this resource. However, it is not strictly required. If you start your repository with a README file using the GitHub interface, your local repository won't have this README file. To prevent encountering an issue while attempting to push your files (as in step 3 of the following section), carry out the following steps to pull that file to your local folder after step 5 (where you setup your local folder as your git repository):

### STEP 3

The following will show up following repository creation.

Image description

STEP 4

Open Git Bash and use the cd command to move the current working directory to your local project.

Image description

STEP 5

Create a Git repository in the local directory.

Image description

STEP 6

Before the initial commit, stage the files by adding them to the local repository using (git add .)

STEP 7

The staged files can be seen with "git status"

Image description

STEP 8

The files you've staged in your local repository should now be committed using ( git commit -m "First commit" )

Image description
Since there is nothing remaining to commit after running the "git status" command, all files have already been committed.

Git Bash paste instructions.

Linux

Type Ctrl+Shift+V

Windows

Consider one of the following options:

  1. Press the Insert+Shift button.

  2. Using the mouse, do the following: Right Click -> Edit -> Paste

  3. Enable the "Quick Edit" mode and use the Ctrl+V shortcut as usual:

Right-click and choose "Properties."
Choose the "Options" tab.
Check the box next to "Quick Edit Mode."
If a "Experimental" tab appears, select it and then check the top "Enable experimental console" and "Enable new Ctrl key shortcuts" options.
To save, click 'OK.'
You can now paste using Ctrl+V.

Conclusion

We were successful in covering Git Bash at a beginner's level and how to use it. When using Git Bash, the commands will be useful.

This has been a long read, if you made it this far then I genuinely hope you find the information useful.
I appreciate your time.


Original Link: https://dev.to/letticia20/git-bash-beginners-guide-4anc

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To