Git commands are essential for version control and managing changes to code repositories. git init initializes a new repository, git add adds changes to the staging area, and git commit records changes to the repository. git status shows the current status of the repository.
Git is a powerful version control system that allows companies like Scrrum Labs to track changes to their code and collaborate with others on software projects. Here are some of the most basic and important Git commands that every developer should know:
git init : It is a Git command that initializes a new Git repository in the current directory. It creates a new .git subdirectory that contains all the necessary files and directories for Git to function. This command should be used when starting a new project and wanting to track changes to the code using Git version control system.
git add .It is a Git command that adds changes made to a file to the staging area. The staging area is a place where changes are tracked before they are committed to the repository. Before committing changes to the repository, it is important to add the files that have been modified or created using git add. This command updates the staging area with the changes made to the file, and prepares it for the next commit.
There are a few different ways to use git add:
git add <file>: This command adds a specific file to the staging area. For example, git add index.html adds the file "index.html" to the staging area.
git add .: This command adds all changes in the current directory to the staging area. It is a shorthand for adding all changes at once.
git add -p : This command allows you to interactively add changes to the staging area. It prompts you to review changes one by one, and decide whether to add them to the staging area or not.
git commit :It is a Git command used to record changes to the repository. It creates a snapshot of the changes made to the files that have been added to the staging area using git add, and adds a commit message describing the changes made.
git commit -m "some message"
Once a commit is created, it becomes a permanent part of the repository's history. The commit message, along with the changes made, is stored in the Git database and can be used to review the history of the repository and understand how the project has evolved over time.
git status :It is a Git command used to display the current status of the repository. It shows which files have been modified or added since the last commit, which files are currently staged and ready to be committed, and which files are not being tracked by Git.
git log: This command shows a list of all the commits made to the repository, along with the author, date, and commit message. It is useful for tracking changes and understanding the history of a project.
git push: This command pushes changes to a remote repository, typically on a hosting service like GitHub or GitLab. It is important to make sure that the local repository is up-to-date before pushing changes to avoid conflicts.
git pull: This command pulls changes from a remote repository into the local repository. It is important to pull changes before making any new changes to avoid conflicts.
git clone: This command creates a copy of a remote repository on your local machine. It is useful for starting a new project or working on an existing project on a different machine.
git branch: This command lists all local branches in the repository. A branch is a separate line of development in a repository. It is useful for working on different features or versions of a project.
git checkout: This command switches between different branches or commits in the repository. It is useful for testing code changes or rolling back to a previous version of the project.
git merge: This command merges changes from one branch into another. It is useful for combining changes from different features or versions of a project.
git stash: This command temporarily saves changes that are not ready to be committed. It is useful for switching branches or pulling changes without losing any work.
git fetch: This command fetches changes from a remote repository without merging them into the local repository. It is useful for checking for changes without pulling them in.
git revert: This command reverts a previous commit by creating a new commit that undoes the changes. It is useful for fixing mistakes or undoing changes that were not intended.
These are just a few of the many Git commands available. Understanding these basic commands is essential for working with Git and collaborating on software projects. With practice, developers can become proficient in using Git to manage code changes and work efficiently with others.