Git is a free, open-source distributed version control software that lets you manage and keep track of your source code history. It was created by Linus Torvalds in 2005. This tool is a version control system that was initially developed to work with several developers on the Linux kernel.
You can download git for your Mac/Windows/Linux at https://git-scm.com/download.
** repository **keeps all your project's files, including commits and branches.
branch is a copy of the repository holding the specific version. The main branch in git is master.
commit is a command used to save changes to the specific branch or repository.
** fork** is a copy of the repository.
checkout is the operation of switching between the current branch and the one specified in the command.
master is the main branch of the repository.
merge is an action that adds changes from one branch to another.
head is the most recent commit of the repository you working with.
Let's have a look at some of the basic git commands:-
$ git config --global user.name "username" $ git config --global user.email "email@example.com"
this command is used to set the current user name and email configuration to be used in commits.
$ git init
this command is used to initialize an empty repository from the folder you are currently using this command.
$ git status
this command is used to check the status of the modified files and it shows which files are staged, unstaged, and untracked.
$ git add "file name"
this command adds a file to the staging area
$ git add .
this command adds all the files to the staging area.
$ git commit -m "commit message"
This command is used to commit all staged changes with the custom message passed as a string. It saves file changes permanently in the version history.
If you want to push those changes to github, then you've to create a new repository 🧡
$ git remote add
this command is used to connect your local repository to the remote server
$ git push -u origin master
this command sends the committed changes of the master branch of your remote repository.
$ git log
this command is used to list the version history for the current branch
git clone "repository-URL"
this command is used to copy or clone the existing repository to the specified folder on your computer.
$ git pull
this command fetches and merges changes on the remotes server to your local working repository.
$ git fetch
this command retrieves the most recent changes from the origin branch but doesn't merge.
$ git branch
this command lists out all the branches in the repository.
$ git branch "branchname"
this command creates a new branch
$ git branch -d "branchname"
this command will delete the branch with the specified branch name.
$ git checkout "branch-name"
this command is used to switch from one branch to another
$ git checkout -b "branch-name"
this command creates a new branch and also switches (checkout) to it.
$ git merge "branchname"
this command merges the branch with the specified branch to the current branch.
$ git revert "commit-hash"
this command creates a new commit that undoes changes made in the specified commit and applies it to the current branch.
$ git reset "filename"
It remotes specifies a file from the staging and leaves the working directory unchanged.
$ git reset --hard "commit"
this command discards all history and goes back to the specified commit
NOTE:- I'll keep updating this article with time & looking to make it more beginners friendly