Beginner's Guide to Version Control & Command Line
Please note that documentation translations may be outdated; try to use English documentation if possible.
- Installing Git
- Recommendations
- Generate-SSH key
- Add an SSH key to your GitHub account
- Clone the repository
- Branches
- Making a Pull Request
git --version
And if the command is not found, then use this: xcode-select --install
git config --global user.name "Practicum"
git config --global user.email [email protected]
git config --list
git config --global core.ignorecase false
Creating folder :
mkdir nameFolder
Moving in folder
cd nameFolder
git init
If you need: delate repository
rm -rf .git
touch file.txt
git add file.txt
Save all file
git add --all
git add .
git commit -m "Text of changes!"
Warning
MUST be on the English layout :q!
consider in detail the service information from the .git folder
Open Terminal and enter the command:
ssh-keygen -t ed25519 -C ""
Next, the command will prompt you to enter the path to the folder where you want to save the key:
Enter file in which to save the key (/Users/practicum/.ssh/id_ed25519)
I recommend agreeing with the proposed option - just press Enter.
Enter a passphrase for the file:
Enter passphrase (empty for no passphrase)
This password will be needed every time you try to print part of the key.
The program offers to create a key without a password; to skip a step, press Enter.
Next, run a command that will add the key to the SSH agent (a program that remembers your private SSH key and automatically substitutes it when you connect to the server via SSH) and saves it in the Keychain:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Now copy the public key id_ed25519.pub to the clipboard:
pbcopy < ~/.ssh/id_ed25519.pub
- Go to GitHub and go to Settings.
- In the left menu, select SSH and GPG keys.
- Click New SSH key or Add SSH key.
- In the Title field, enter the name of the key (for example, the name of your computer).
-
In the Key field, paste the key from the clipboard using the hot keys Cmd + V.
-
Click Add SSH key.
Open a terminal and go to your projects folder
- Open your project in GitHub, click the green Code button and copy the project's SSH address
Open a terminal and go to your projects folder: git clone [email protected]:/first-project-git.git second-project-git cd second-project-git
Before performing a git pull, make sure that your working version is clean, that is, all changes are committed: a commit is made.
Sometimes, after running a git pull, merge conflicts can arise if the same parts of code have been changed locally and in the remote repository. In this case, Git will ask you to resolve these conflicts before continuing.
Warning
Before performing a git pull, make sure that your working version is clean, that is, all changes are committed: a commit is made. Sometimes, after running a git pull, merge conflicts can arise if the same parts of code have been changed locally and in the remote repository. In this case, Git will ask you to resolve these conflicts before continuing.
git branch - view project branches
git branch <branch_name>: create a branch
git checkout <branch_name>: switch between branches
You can create a branch and immediately start working on it
git checkout -b another_branch
Merging the branches
git merge new_branch
latest changes from master branch to remote repository
git push -u origin main
you don't have to go to a branch to push it
git push -u origin merge-request
- Go to the repository page and select the Pull requests tab and click the green New pull request button. Select the names of the branches: the “to” branch (to which the pull request will be sent) and the “from” branch (from which the pull request will go).
The window will display the added commits and their changes. Click Create pull request.
Fill in the fields with the name and description of the pull request. Click Create pull request.
Now you or your colleagues can go to the Files changed tab to leave your comments and conduct a review.
All that remains is to click Merge pull request. This will merge the branch with your changes and the main branch.