What is Git
Git is a free, open-source and version control system. By using Git you can see what changes have been made to the project code.
What is a GIT Repository
Git repository is the .git/ folder inside a project. This repository tracks all changes made to files in your project, building a history over time. Meaning, if you delete the .git/ folder, then you delete your project’s history.
There are two repository:
- local repository
- remote repository
local repository has three different stages. Those are:
- Working directory
- staging area
- Local Repo
working directory is where new files are created, old files are deleted, or where changes are made to already existing file
Once changes are made, they are added to the staging area.
Once the changes are complete, the staging area will contain one or more files that need to be committed. Creating a commit will cause Git to take the new code from the staging area and make the commit to the main repository. This commit is then moved to the Local Repo.
Getting started with Git:
- git init is one way to start a new project with Git
- git add is a command used to add files that is in the working directory to the staging area.
git add -A # stages all changes. git add . # stages new files and modifications, without deletions (on the current directory and its subdirectories). git add -u # stages modifications and deletions, without new files
- git commit is a command used to add all files that are staged to the local repository.
git commit -m "add a commit message here"
- git push is a command used to upload/push local repository content to a remote repository. In the remote repository, all files and changes will be visible to anyone.
git push remote_url branch_name git push remote_url branch_name -force #git force push allows you to push local repository to remote without dealing with conflicts
- git fetch is a command used to get files from the remote repository to the local repository but not into the working directory.
git fetch repository Url git fetch branch_URL branch _name #To fetch a specific branch
- git merge is a command used to get the files from the local repository into the working directory.
- git pull is a command is used to fetch and download content from a remote repository to local repository. It is equivalent to a git fetch and a git merge .
git pull remote branch URL git pull remote/branchname (Recommended)
- git status is a command lets you see which changes have been staged
- Git log is a utility tool to review and read a history of everything that happens to a repository.
- git –version is a command used to check git version
- Configure your Git username and email address.
git config --global user.name "YOUR_USERNAME" git config --global user.email "email@example.com" git config --global --list # To check the info you just provided