What is Git
Git is a distributed version control system used for tracking changes in source code during software development. It allows multiple developers to work on the same project simultaneously while keeping track of all changes made to the codebase.
Commands
Generate SSH key Github
cmd ---> ssh-keygen
# Add SSH key (pub) to github
# Copy directory desired with ssh
# Initial Setup (From Computer)
1. mkdir NEW-FILE ---> Create the inital Repo
2. git config --global user.name USERNAME ---> Add the Git Username
3. git config --global user.email EMAIL(GITHUB EMAIL) ---> Add the Git Email
4. git init -b main ---> Create the main branch
# Initial Setup Connect files created to Github repo
1. git remote add origin 2. git@github.com:hacking-notes/FOLDER
3. git push -u origin main
# Initial setup Connect to Github repo
1. git clone GIT-URL-SSH ---> Clone repo (Add SSH)
2. git pull ---> Get latest changes
3. git push ---> Push latest changes (after commit)
# Get status (See current new changes)
- git status ---> Tell you the current status of your files
# Add files to be commited
- git add FILE ---> Add file to the futur commit
# Commit
git commit -m "Commit Message" ---> Commit to the repo
git commit -am "Fixed XYZ" ---> Automaticly commit know files
# Logs
- git log ---> Get logs (History of the repo)
- commit (FILE HASH) (HEAD) ---> Head = Current
- Info User who push
- Date
- git log --online ---> display just the most important information
- git log --online --graph ---> Show a graph to see mergure
# Diff
git diff FILE ---> Show the different changes to this file
# Adding notes & Extra information
git notes add ---> Add note to the most recent commit
git notes edit ---> Edit the currents notes
git notes remove ---> Remove the current notes
# Remove
git rm FILE ---> Remove a file in the git commit reprository
# Restore
git restore FILE ---> Restore a file
git reset HASH ---> Restore to X version
# Branches
- git branch ---> Show the current branch
- git checkout -b experimentation ---> (Create a new branch)
- git checkout BRANCH-NAME ---> change branch
- git checkout - ---> Change for the latest branche
- git switch (like git checkout)
# Stach (changes but not commited) - (Save changes without commit)
- git stash ---> Save changes changes (Temporary place)
- git stash pop ---> Add unsaved changes
- git stach push -m "not finish" ---> Add notes when creating stach
- git stach list ---> See all the unsaved stash
- git stash pop --index NUMBER ---> Select a specific stash in the list
- git stash drop ---> Remove the other stash
# Merge (merging branch)
- git merge branch-to-merge ---> Add all the stuf to this branch + commit
- git merge --squash branch ---> Merge branch but does not commit
- git branch -D BRANCH ---> Delete a branch
- git cherry-pick HASH ---> Specify the merging hash