how to set git
- User
how to set git
- Assistant
how to set git
Setting up Git involves a few initial configuration steps to ensure that it works smoothly for your projects. Below are the steps to get you started, including installation and basic configuration.
Windows:
macOS:
brew install git
Linux:
sudo apt update
sudo apt install git
sudo yum install git
sudo pacman -S git
To check if Git is installed properly, open your terminal (or Git Bash on Windows) and run:
git --version
You should see the installed version of Git.
You need to set your user name and email address, which will be associated with your commits.
Set your username:
git config --global user.name "Your Name"
Set your email:
git config --global user.email "your_email@example.com"
To see your configuration, you can run:
git config --list
This command will display all the settings you have configured.
To create a new Git repository, navigate to the folder you want to make a repository in and run:
git init
If you want to clone an existing repository, use:
git clone https://github.com/user/repository.git
Here are some basic commands to get you started:
Add changes to staging area:
git add <file> # to add a specific file
git add . # to add all changes
Commit changes:
git commit -m "Your commit message"
Check the status of your repository:
git status
View commit history:
git log
If you are using services like GitHub, GitLab, or Bitbucket, setting up SSH can save you from entering your username and password every time you push or pull.
Generate an SSH key:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Follow the prompts to save the key.
Add your SSH key to your SSH agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
Copy the SSH key to your clipboard:
pbcopy < ~/.ssh/id_rsa.pub
xclip -sel clip < ~/.ssh/id_rsa.pub
clip < ~/.ssh/id_rsa.pub
Add the SSH key to your Git service provider's account (e.g., GitHub/GitLab/Bitbucket).
Now you're all set up to start using Git! Ensure to explore more advanced features and commands to make the best use of Git's capabilities.
Not yet included in a published release.