Git Fundamentals

Git is a distributed version control system used to track changes in source code during software development. Below are some fundamental Git concepts and commands:

1.git init

Thegit initcommand initializes a new Git repository in the current directory.

git init    # Initializes a new Git repository

2.git clone

Thegit clonecommand creates a copy of an existing repository.

git clone https://github.com/user/repository.git    # Clones a repository from GitHub

3.git add

Thegit addcommand stages changes for the next commit.

git add file.txt       # Stages a specific file for commit
    git add .                # Stages all changes in the current directory

4.git commit

Thegit commitcommand commits the staged changes to the repository with a descriptive message.

git commit -m "Commit message"    # Commits changes with a message

5.git status

Thegit statuscommand displays the status of changes in the working directory and staging area.

git status    # Shows which files are staged, unstaged, or untracked

6.git log

Thegit logcommand shows the commit history for the repository.

git log    # Displays a list of commits with their messages and details

7.git diff

Thegit diffcommand shows the differences between the working directory and the index, or between different commits.

git diff           # Shows changes between working directory and index
    git diff HEAD        # Shows changes between working directory and the last commit

8.git branch

Thegit branchcommand lists, creates, or deletes branches.

git branch               # Lists all branches
    git branch new-branch    # Creates a new branch

9.git checkout

Thegit checkoutcommand switches branches or restores working directory files.

git checkout branch-name   # Switches to the specified branch
    git checkout -b new-branch   # Creates and switches to a new branch

10.git merge

Thegit mergecommand merges changes from one branch into the current branch.

git merge branch-name   # Merges the specified branch into the current branch

11.git pull

Thegit pullcommand fetches changes from a remote repository and merges them into the current branch.

git pull    # Fetches and merges changes from the remote repository

12.git push

Thegit pushcommand uploads local commits to a remote repository.

git push    # Pushes commits to the remote repository

13.git remote

Thegit remotecommand manages remote repositories.

git remote -v    # Lists remote repositories
    git remote add origin https://github.com/user/repository.git   # Adds a new remote repository

14.git reset

Thegit resetcommand undoes changes by moving the HEAD pointer and optionally modifying the working directory.

git reset HEAD~1    # Resets to the previous commit
    git reset --hard HEAD~1   # Resets and discards changes in the working directory

15.git revert

Thegit revertcommand creates a new commit that undoes the changes from a previous commit.

git revert commit-id    # Reverts changes made by the specified commit

You are here for...

I think you are here to get to know me.

🌐 Connect with me across platforms.

🤝 Hit me up on these links, and let's turn ideas into action!