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 initThegit initcommand initializes a new Git repository in the current directory.
git init # Initializes a new Git repositorygit cloneThegit clonecommand creates a copy of an existing repository.
git clone https://github.com/user/repository.git # Clones a repository from GitHubgit addThegit 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 directorygit commitThegit commitcommand commits the staged changes to the repository with a descriptive message.
git commit -m "Commit message" # Commits changes with a messagegit statusThegit statuscommand displays the status of changes in the working directory and staging area.
git status # Shows which files are staged, unstaged, or untrackedgit logThegit logcommand shows the commit history for the repository.
git log # Displays a list of commits with their messages and detailsgit diffThegit 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 commitgit branchThegit branchcommand lists, creates, or deletes branches.
git branch # Lists all branches
git branch new-branch # Creates a new branchgit checkoutThegit 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 branchgit mergeThegit mergecommand merges changes from one branch into the current branch.
git merge branch-name # Merges the specified branch into the current branchgit pullThegit pullcommand fetches changes from a remote repository and merges them into the current branch.
git pull # Fetches and merges changes from the remote repositorygit pushThegit pushcommand uploads local commits to a remote repository.
git push # Pushes commits to the remote repositorygit remoteThegit remotecommand manages remote repositories.
git remote -v # Lists remote repositories
git remote add origin https://github.com/user/repository.git # Adds a new remote repositorygit resetThegit 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 directorygit revertThegit revertcommand creates a new commit that undoes the changes from a previous commit.
git revert commit-id # Reverts changes made by the specified commitI 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!