Basic Git Commands and Concepts
Installation:
Windows: Download from and follow the installation steps.
Mac: Use Homebrew -
brew install git.Linux: Use the package manager -
sudo apt-get install git(Debian/Ubuntu) orsudo yum install git(Red Hat/Fedora).
Configuration:
shgit config --global user.name "Your Name" git config --global user.email "your.email@example.com"Creating a Repository:
shgit initCreates a new Git repository in the current directory.
Cloning a Repository:
shgit clone <repository_url>Creates a local copy of a remote repository.
Staging Changes:
shgit add <file_name> git add .Adds files to the staging area. The period (
.) stages all changes.Committing Changes:
shgit commit -m "Commit message"Records changes to the repository with a descriptive message.
Checking Status:
shgit statusShows the status of changes in your working directory.
Viewing Commit History:
shgit logDisplays the commit history of the repository.
Branching:
shgit branch git branch <branch_name> git checkout <branch_name>git branch: Lists branches.git branch <branch_name>: Creates a new branch.git checkout <branch_name>: Switches to the specified branch.
Merging:
shgit checkout <target_branch> git merge <source_branch>Merges changes from the source branch into the target branch.
Pulling Changes:
shgit pullFetches and merges changes from the remote repository to your local repository.
Pushing Changes:
shgit pushUploads your local repository changes to the remote repository.
Common Workflow Example
Create/Clone a Repository:
shgit clone https://github.com/your_username/repository_name.git cd repository_nameCreate a Branch:
shgit checkout -b new_featureMake Changes and Stage Them:
shgit add .Commit Changes:
shgit commit -m "Added new feature"Push Branch to Remote:
shgit push origin new_featureCreate a Pull Request on your remote repository platform (GitHub, GitLab, etc.)
Merge Changes after review:
shgit checkout main git pull git merge new_feature