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:
git init
Thegit init
command initializes a new Git repository in the current directory.
git init # Initializes a new Git repository
git clone
Thegit clone
command creates a copy of an existing repository.
git clone https://github.com/user/repository.git # Clones a repository from GitHub
git add
Thegit add
command 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
git commit
Thegit commit
command commits the staged changes to the repository with a descriptive message.
git commit -m "Commit message" # Commits changes with a message
git status
Thegit status
command displays the status of changes in the working directory and staging area.
git status # Shows which files are staged, unstaged, or untracked
git log
Thegit log
command shows the commit history for the repository.
git log # Displays a list of commits with their messages and details
git diff
Thegit diff
command 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
git branch
Thegit branch
command lists, creates, or deletes branches.
git branch # Lists all branches
git branch new-branch # Creates a new branch
git checkout
Thegit checkout
command 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
git merge
Thegit merge
command merges changes from one branch into the current branch.
git merge branch-name # Merges the specified branch into the current branch
git pull
Thegit pull
command fetches changes from a remote repository and merges them into the current branch.
git pull # Fetches and merges changes from the remote repository
git push
Thegit push
command uploads local commits to a remote repository.
git push # Pushes commits to the remote repository
git remote
Thegit remote
command manages remote repositories.
git remote -v # Lists remote repositories
git remote add origin https://github.com/user/repository.git # Adds a new remote repository
git reset
Thegit reset
command 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
git revert
Thegit revert
command creates a new commit that undoes the changes from a previous commit.
git revert commit-id # Reverts changes made by the specified commit
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!