Git
Configuring Git
SSH одновременно с GitHub и Gitlab
Для работы с одной системы с тем и другим репозиторием по SSH нужно создать ключи SSH под оба, а также прописать в файле конфигурации профили подключения:
Для проверки работоспособности конфигурации можно подключиться с помощью ssh напрямую:
Для избежания ошибок следует:
- В имени ключа не использовать знак тире
- - Сначала клонировать удалённый репозиторий с помощью
git clone, далее локально его обновить и синхронизировать с помощьюgit push origin main
Cloning Repository
Initialising Local & Remote Repo
Cloning Remote Repo on Amazon
Certificate file needed in .ssh folder. Also a config file .ssh/config is needed:
Git commands to clone repo:
Branching
Create new branch: git branch new-branch
Pointer does not automatically switch to new branch, it is left on main branch, so you need to switch manually: git checkout new-branch
Merging Branches
- Switch to branch for merging
- Merge
- Check pointers point to one place OR merge the other branch with the current one
Change of branches to make it look as if the functionality was developed step-by-step, not in parallel.

Pointer
HEAD is the pointer to current project state. By default HEAD points to current branch.
You can go back by commits or by direct commit hash:
git checkout C1
You can use syntax “^K” for going up 1 level (where K is the route number to choose if there are more than 1 parent. By default, K=1) and “~N” for N steps up:
Chaning main branch to several commits backwards:
Undo Actions
For 1-person local repo do reset. For multi-person remote repo, do revert.
In c2’ state are the changes, which cancel state C2
Moving commits
Chosen commits are moved upon current commit using cherry-pick command. Used when it is known what specific commits to move: git cherry-pick C2 C4
git rebase -i HEAD~4 --aboveAll

Small commit modifications
You can modify a commit, dividing it into two with same parent:
git commit --amend
Tagging commits
Marking milestones is done with tags. They block the commit from changes, moving etc.:
Tags serve as anchors in tree of commits. To define your position against the nearest anchor, use command:
Naming
Remote branches have a naming convention: <remote name>/<branch name>
Main remote i called origin. So master branch is origin/main. When doing commit in local branch, the system is put into detached HEAD mode:
Fetch data from remote repository
When data is downloaded from remote repo, the origin/main branch is updated to reflect the new commits:
git fetch
Only commits non-present locally are downloaded. No local state of files is changed after download. The local main status is unchanged. To change, a merge must be done:
git fetch + git merge = git pull
git pull
Publishing local repository to remote
Publishing syncs commits at remote repo and local repo (main and origin/main point to the same commit):
git push
If the remote repo has changed by someone by the time you need to push there, it means that your feature is based on an old commit. So Git will not let you push. Before push, a fetch must be made to sync the changes, than a rebase or merge to update the main branch, and then a push:
git fetch + git rebase origin/main + git push OR git fetch + git merge origin/main + git push = git pull –rebase
git pull --rebase
Changing main and origin/main
You can change that another branch will be main for the remote repo: `git checkout -b side origin/main
Push arguments
You can specify what branch to push:
git push origin main
origin = remote repo, main = branch to take commit from.
It does not matter where the HEAD is at this moment. You can specify where to push commits using git push origin <source>:<destination> notation:
git push origin side^2:master
If push is made to a non-existent branch on remote repo, Git will create this branch:
git push origin main:newBranch
Fetch arguments
Same as push, but the other wat around. Go to foo branch on remote repo, download commits from there to local branch origin/foo:
git fetch origin foo

