cd to project dir.
Note
Optional: create a file .gitignore and add all file endings, relative paths and/or file names not to be included to the repository.
Then
git initInitializes the repo with branch main.- Optional:
git init -b <branch name>Initializes the repository with a custom branch name.
- Optional:
git add .Add (stage) everything not excluded by .gitignore.git commit -m '<commit message>'Commit all staged changes inlcuding a commit message.git remote add origin <url>Add remote location like Github, Gitlab or whatev.git push origin mainPush branch main to origin.
Tip
To stages all changed and tracked files excluding untracked files and commit them all with a single command use the git commit option -a | --all like git commit -a -m <commit message>.
Create a new branch
git branch -b <branch name>
Switch to the new branch
git checkout <branch name>
Delete a specific branch
git branch -D <branch name>
This resets the project to the state of the latest commit inlcuding local files and the commit history itself.
git reset --hard HEAD
git reset --hard <commit hash>
Get commit hash to revert to using git log --oneline.
Staging specific files
git add <file name or directory>
Checking current status
git status
Display commit history
git log
git log --oneline # output single line style