Git bash basic command.
cd #change directory.
pwd #shows your present working directory.
touch filename #new file will be created
ls #list all the files of that directory.
clear #to clear the bash terminal
Helps us to initialize a git in the current directory.
The “clone” command downloads an existing Git repo to your local computer.
Specifies the URL of the remote repository.
The “add” command marks changes to be included in the next commit.
Specifies the files you want to add to the Staging Area.
recursively added all files of the current directory.
recursively added all files of the current directory.
stage (modified and deleted) files.
add all files in current dir, except for files whose name begins with a dot.
The “status” command helps you understand the current state of your repo.
The “commit” command is used to save your changes to the local repo.
Sets the commit’s message.
Includes all currently changed files in this commit.
Update the last commit message.
-a -m " message "
direct commit to tracked file.
The “push” command is used to publish new local commits on a remote server.
Pushes all local branches.
Pushes all local tags.
Deletes the specified remote branch.
-u origin master
is useful when publishing a local branch on a remote for the first time.
The “pull” command is used to download and integrate remote changes.
The “rm” command helps you to remove files from a Git repository.
The name of a file (or multiple files) you want to remove.
Removes the file only from the Git repo, but not from the filesystem.
The “restore” command helps to unstage or even discard uncommitted local changes.
The name of a file (or multiple files) you want to restore.
-- stage <filename>
Removes the file from the Staging Area, but leaves its actual modifications untouched.
— source <ref>
Restores a specific revision of the file.
Allows you to select individual chunks to restore.
The “switch” command allows you to switch your current HEAD branch. It’s relatively new (added in Git v2.23) and provides a simpler alternative to the classic “checkout” command.
The name of a local or remote branch that you want to switch to.
The name of a new local branch you want to create.
<branch-name> — discard-changes
Switch to the specified branch and discard any local changes to obtain a clean working copy.
Switch back to the previous branch. When specifying just the “-” character instead of a branch name, Git will switch back to the last checked-out branch.
The “remote” command helps you to manage connections to remote repositories.
Shows URLs of remote repositories when listing your current remote connections.
add <shortname> <url>
Creates a new connection to a remote repository.
Disconnects the remote from the local repository.
rename <old-name> <new-name>
Renames the remote connection.
The “revert” command helps you undo an existing commit.
Specifies the commit that you want to undo.
Do not directly commit the created changes
Use the default commit message that Git suggests.
The “branch” command helps you create, delete, and list branches.
Create a new branch called a branch.
Delete thrspecified branch.
Force delete the specified branch, even if it has unmerged changes.
Rename the current branch to branch
List all remote branches
The “checkout” command can switch the currently active branch — but it can also be used to restore files.
The name of a local branch that you want to switch to.
Creates a new local branch and directly switches to it.
To go back to the master branch
Restores a historic revision of a given file.
The “merge” command lets you take the independent lines of development created by the git branch and integrate them into a single branch
Creates a merge commit even when a fast-forward would be possible.
Combines all integrated changes into a single commit, instead of preserving them as individual commits.
When a conflict occurs, this option can be used to abort the merge and restore the project’s state as it was before starting the merge.
The “git log” tool allows you to view info about previous commits that have occurred in a project.
This command helps us to get info about which file is added or removed from the current directory
will give all the stat of all add or delete done in the directory.
all commits will show in online only.
u will get the commit as per your mentioned duration eg 2days/1week/1year.
The “config” command is a convenience function that is used to set Git configuration values on a global or local project level.
git config levels and files
Before we further discuss “git config” usage, let's take a moment to cover configuration levels. The “git config” command can accept arguments to specify which configuration level to operate on. The following configuration levels are available:
By default, “git config” will write to a local level if no configuration option is passed. Local-level configuration is applied to the context repository “git config” gets invoked in.
Global level configuration is user-specific, meaning it is applied to an operating system user.
System-level configuration is applied across an entire machine. This covers all users on an operating system and all repos. The system-level configuration file lives in a gitconfig file off the system root path.
list of all configuration
displays the username
<--global/ — local/ — system> user.email
displays the user mail id
<-- global> alias.<aliasname> <originalgitcmd>
To set an alias name globally.
rm -rf .git
This “rm -rf .git” command helps us to remove the initialized git repo.