WHAT IS GIT?
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 git-scm.com/download.
SOME BASIC TERMS:-
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.
BASIC GIT COMMANDS
Let's have a look at some of the basic git commands:-
GIT CONFIG
$ git config --global user.name "username"
$ git config --global user.email "user@email.com"
this command is used to set the current user name and email configuration to be used in commits.
GIT INIT
$ git init
this command is used to initialize an empty repository from the folder you are currently using this command.
GIT STATUS
$ 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
$ 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
$ 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
$ git remote add
this command is used to connect your local repository to the remote server
GIT PUSH
$ git push -u origin master
this command sends the committed changes of the master branch of your remote repository.
GIT LOG
$ git log
this command is used to list the version history for the current branch
GIT CLONE
git clone "repository-URL"
this command is used to copy or clone the existing repository to the specified folder on your computer.
GIT PULL
$ git pull
this command fetches and merges changes on the remotes server to your local working repository.
GIT FETCH
$ git fetch
this command retrieves the most recent changes from the origin branch but doesn't merge.
GIT BRANCH
$ 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
$ 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
$ git merge "branchname"
this command merges the branch with the specified branch to the current branch.
GIT REVERT
$ 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
$ 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
Resources:-
NOTE:- I'll keep updating this article with time & looking to make it more beginners friendly