How to use Git Bash?
Git Bash is a powerful tool that allows you to interact with the Git version control system in a command-line environment on Windows. Let’s go through the basics of How to use Git Bash
Step 1: Configuring Git
Set your global username/email configuration
Open Git Bash and begin creating a username and email for working on Git Bash.
Set your username:
git config --global user.name "FIRST_NAME LAST_NAME"
Set your email address:
git config --global user.email "MY_NAME@example.com"
cd command refers to the command line change directory and is used to get into the desired directory. To navigate between the folders the cd command is used
cd folder_name
ls command
ls command is used to list all the files and folders in the current directory.
ls
Open Git Bash and change the current working directory to your local project by use of the cd command.
Step 2: Commit Repository in Git Bash
Initialize the local directory as a Git repository.
git init
Stage the files for the first commit by adding them to the local repository
git add .
By “git status“ you can see the staged files after that Commit the files that you’ve staged in your local repository.
git commit -m "First commit"
Now After the “git status” command, it can be seen that nothing to commit is left, Hence all files have been committed.
Step 3: Initializing a Local Git Repository
Follow the steps given below to initialize your Local Repository with Git.
Open GitHub through the internet and click on create new repository Give a suitable name for your repository and create the repository.
Note: You can choose to initialize your git repository with a README file, and further, you can mention your project details in it. It helps people know what this repository is about. However, it’s absolutely not necessary. But if you do initialize your repo with a README file using an interface provided by GitHub, then your local repository won’t have this README file.
The following will appear after creating the repository
Step 4: Connect the local Repository to GitHub
Go to the GitHub repository and in the code, section copy the URL and In the Command prompt, add the URL for your repository where your local repository will be pushed.
git remote add origin repository_URL
Push the changes in your local repository to GitHub.
git push origin master
Here the files have been pushed to the master branch of your repository. Now in the GitHub repository, the pushed files can be seen.
Step 5: Pulling and Pushing Changes to GitBash
Suppose the files are being changed and new files are added to the local repository. To save the changes in the git repository:
Download all the other changes from the remote repository to the local repository.
git pull
Changes have to be staged for the commit.
git add .
or
git add file_name
Now commit the staged files.
git commit -m "commit_name"
Push the changes.
git push origin master
New changes can be seen:
Git Bash
Git Bash is an essential tool that provides Git command line experience on the Windows Operating System. It is a command-line shell for enabling Git with the command line in the system. Git Bash is a package that installs a Bash emulation, some common Unix utilities, and Git on a Windows operating system. In Git Bash the user interacts with the repository and git elements through the commands.
Table of Content
- What is Git?
- What is Git Bash?
- Git GUI
- How to Install Git Bash?
- Git Bash Commands
- How to use Git Bash?
- How to Create and Manage Branches in GitBash?
- Merging Branches in GitBash
- Cloning Repositories in GitBash
- Undoing Commits in GitBash
- Conclusion
- FAQs On GitBash