Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Git is a powerful version control system used by developers worldwide to manage and track changes in their codebase. Understanding Git commands is crucial for efficient collaboration and maintaining a clean project history. This article will guide you through essential Git commands, demonstrating their usage in a Linux environment. Whether you're a beginner or looking to refine your skills, mastering these commands will significantly enhance your workflow.
Examples:
Setting Up Git: Before you start using Git, you need to configure your Git environment. This involves setting your username and email address, which will be associated with your commits.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Initializing a Repository: To start tracking your project with Git, you need to initialize a new repository.
mkdir my_project
cd my_project
git init
Cloning a Repository: If you want to work on an existing project, you can clone a repository from a remote server.
git clone https://github.com/username/repository.git
Staging and Committing Changes: Once you've made changes to your files, you need to stage them before committing.
git add .
git commit -m "Initial commit"
Checking the Status: To see the status of your working directory and staging area, use the following command:
git status
Viewing the Commit History: To view the history of commits in your repository, use:
git log
Branching and Merging: Branches allow you to work on different features or fixes independently. Here’s how to create and switch to a new branch:
git branch new-feature
git checkout new-feature
After making changes and committing them, you can merge the branch back into the main branch:
git checkout main
git merge new-feature
Pushing and Pulling Changes: To share your changes with others, you need to push them to a remote repository. Similarly, to update your local repository with changes from others, you pull from the remote repository.
git push origin main
git pull origin main
Resolving Conflicts: Sometimes, you may encounter merge conflicts. Git will mark the conflicting areas in the files, and you’ll need to resolve them manually.
# Edit the conflicting files to resolve conflicts
git add resolved_file
git commit -m "Resolved merge conflict"