What is git ?
Git is a free and open-source version control system that can handle both small and large projects with ease.
Git is easy to learn and has a small footprint while providing lightning-fast performance. It offers more features than Subversion, CVS, Perforce, and ClearCase, such as cheap local branching, convenient staging areas, and multiple workflows.
Basic commands of GIT
A convenient way to configure your Git installation. On a new development machine, you’ll typically only need to use this right after installing Git.
You can use this command to specify the author name and email address for each of your commits.
Usage: git config — global user.name “<name>”
Usage: git config — global user.email “<email address>”
Creates/initializes a new Git repository. It is the first command you need to know if you want your project to be under revision control.
This command is used to start a new repository.
Usage: git init <repository name>
Copies a Git repository. The most common method for developers to get a working copy of a central repository is by cloning.
This command is used to obtain a repository from an existing URL.
Usage: git clone <URL>
Changes are moved from the working directory to the staging area. As a result, you can prepare a snapshot before committing it to the official history.
This command adds a file to the staging area.
Usage: git add <file_name>
This command adds one or more to the staging area.
Usage: git add *
Commits the staged snapshot to the project history. Together with git add, this defines the basic workflow for all Git users.
This command records or snapshots the file permanently in the version history.
Usage: git cammit <file_name> -m “type in the commit massage”
This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.
Usage: git cammit -a
This displays the state of the working directory and the staged snapshot. To see what’s included in the next snapshot, you’ll also want to run git add and git commit.
This command lists all the files that have to be committed.
Usage: git status
It is used to view expanded details about Git objects such as blobs, trees, tags, and commits. Each object type has its own behavior. Tags show additional objects that are associated with the tag. In a tree, names and content of objects are displayed.
This command shows the metadata and content changes of the specified commit.
Usage: git show
Usage: git show <commit >
Provides access to previous revisions of a project. Provides a variety of formatting options for displaying committed snapshots.
This command is used to list the version history for the current branch.
Usage: git log
The oneline option displays the output with one commit per line.
Usage: git log — oneline
You can use this command to perform general branch administration tasks. This command allows you to create isolated development environments within one repository.
This command lists all the local branches in the current repository.
Usage: git branch
Usage: git chechout -b <branch_name>
This command creates a new branch and switch also in the new baranch.
Usage: git branch -d <branch_name>
This command deletes the feature branch.
Besides allowing you to check out old commits and file revisions, git checkout also allows you to navigate existing branches. Combined with the basic Git commands, it provides a way to work on a particular line of development.
This command is used to switch from one branch to another.
Usage: git checkout <branchname>
Merging is Git’s way of putting a forked history back together again. You can merge the independent lines of development created by git branch by using the git merge command.
This command merges the specified branch’s history into the current branch.
Usage: git merge <branch_name>
You can check by the “git log –oneline” as you see in the image before merging and after merging
This command shows the file differences which are not yet staged.
Usage: git diff <first_commit> <second_commit>
This is builtin command to cleanup the untracked files. Be careful with this one, it deletes files permanently!
Always add -n or — dry-run options to preview the damage you’ll do!
- If you just clean untracked files, run git clean -f
- If you want to also remove directories, run git clean -f -d
- If you just want to remove ignored files, run git clean -f -X
- If you want to remove ignored as well as non-ignored files, run git clean -f -x
Usage: git clean <option>
This command deletes the file from your working directory and stages the deletion.
Usage: git clean <option>
This command is used to connect your local repository to the remote server.
Usage: git remote add <variable_name> <remote_server_link>
After this you can push your files in GitHub by git push command
Usage: git push <variable_name> <branch(master)>
This command fetches and merges changes on the remote server to your working directory.
Usage: git pull <repository_url>