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 an essential tool for version control, widely used in software development to manage code changes. For Apple users, particularly those on macOS, Git is highly relevant as it integrates seamlessly with the Unix-based operating system. This article will guide you through the basic Git commands on macOS, ensuring you can manage your repositories efficiently. We'll cover installation, configuration, and common commands, providing examples to illustrate their use.
Examples:
Installing Git on macOS: macOS often comes with Git pre-installed. To check if Git is installed, open Terminal and type:
git --version
If Git is not installed, you can install it using Homebrew, a popular package manager for macOS. First, install Homebrew by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then, install Git with:
brew install git
Configuring Git: After installation, configure your Git settings. Set your username and email, which will be associated with your commits:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Creating a New Repository: To create a new Git repository, navigate to your project directory and initialize the repository:
cd /path/to/your/project
git init
This command creates a .git
directory that tracks your project changes.
Cloning an Existing Repository:
To clone an existing repository, use the git clone
command followed by the repository URL:
git clone https://github.com/username/repository.git
Basic Git Workflow:
git add filename
To add all changes:
git add .
git commit -m "Your commit message"
git push origin main
Checking Status and Logs:
git status
git log
Branching and Merging:
git branch new-branch
git checkout new-branch
git checkout main
git merge new-branch
Handling Conflicts: If you encounter merge conflicts, Git will mark the conflicts in the affected files. Open these files, resolve the conflicts, then add and commit the changes:
git add conflicted-file
git commit -m "Resolved merge conflict"