Git Commands
Git Commands
#After everything is set, the first thing we have to do is to configure git
with our name and email:
git config --global user.name "<USER_NAME>"
git config --global user.email "<USER_EMAIL>"
Now to check your progress :-
git config --list
The following should be there:
user.name=name
[email protected]
Now setting up your Git Repository
cd desktop
mkdir hello
cd hello
# Now we’re ready to initialize a brand new git repository.
git init ( git init command to initialize the repository:)
# We can check for the current status of the git repository by using
git status ( Now use a git status command to show the status of the
working tree:)
# We can check if there is any file in the directory by
- ls (if linux ls -a )
#to go to previous directory we use
cd ..
# Create and commit a new file
touch hello.txt
#To "register" the file for committing we need to add it to git using
git add hello.txt
# Checking for the status now indicates that the file is ready to be
committed:
git status
# We can now commit it to the repository
git commit -m "Add my first file"
# Now open the file through git bash
notepad hello.txt ( for visual code code hello.txt )
#To discover why, when and by whom a certain line was added
git blame hello.txt
#To abort current uncommitted changes and restore the working copy to
the last committed state:
# Types of reset:
git reset --soft
git reset
git reset --hard
#To remove a file from staging area we use
git reset HEAD ~filename~
#To view the statistics and facts about the last commit:
git show
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status