For learning Git: /sandbox/git-sandbox
Creating a repo
git init
Branches
Show branches: git branch
, also shows the active one.
By default, main exists.
Creating a new branch: git branch <new-branch-name>
When a new branch is created, by default it holds all the files.
Switching the branch: git checkout <new-branch-name>
Can be done in one step: git checkout -b feature/new-functionality
Merge two branches togehter: git merge <another-branch>
If both branches have files, the other branch(es) don’t have, and merge is used, the files will not be interchanged. Rather, the branch we are in will pull the missing files from the branch b). Branch b) will not directly receive the files from a).
Remote repos
git remote -v
Then, you can push to diverse remote repos like this: git push <remote-name> <branch>
Pull: git pull <remote-name> <branch>
Differences between
Commit
git commit -m
with message
git commit -a
stage all altered files
-am
combining both
Staging means to add the files to the commit, as one can do it with git add
Does not work for initial repos, but for files, previously tracked.
See previous commits:
git log
Authorizing github
The easiest way at the moment seems to be: gh auth login
, after apt install gh
Undo commits
This will only undo the commit, but keep the changes:
git reset HEAD~1
Changes will be unstaged.
Remove the commit and its changes to files: git reset --hard HEAD~1
Changing commits
Be aware of Vim here. Save the buffer with :update