git

By | April 4, 2020

In this article, you can learn different errors faced while working with git.

Git errors:

1. fatal: refusing to merge unrelated histories

Solution:

If you get this error, you can use the command “–allow-unrelated-histories” to solve it.

Syntax:

2. file path too long error

Solution:

Above error can be resolved by using below command.

 

Command to set name and email in git:

git config –global user.name “Ronan”
git config –global user.email “ronan@gmail.com”

To see the global configuration settings.
git config –global –list

git saves settings in this config file.
cat ~/.gitconfig

Command to create a repository:
git init project1
Output: Initialized empty Git repository in C:/Users/Ronan/project1/.git/

Command to know whether git is tracking a file or not?
git status

Command to add file in git.
git add filename.extension
This command adds file to the staging area.

Command to commit changes in git.
git commit -m “first commit”
Commits all files present under staging area.
-m is the parameter to provide commit message name.

git add file1.txt
git commit -m “second commit”
Above two operations can be done in single line as below.
git commit -am “second commit”
In -am: a is to add file and m is to provide commit message.

We have few new files in the directory and how do we add it to staging area in a single command?
git add .

Command to see all the commits in one line.
git log –oneline –graph –decorate –color

Command to remove a file in git.
git rm filename

Command to create a directory.
mkdir folder-name

Leave a Reply

Your email address will not be published. Required fields are marked *