- SSH authentication:
git clone [email protected]:IcarusPoliTO/repo-name.git
- HTTPS authentication:
git clone https://github.com/IcarusPoliTO/repo-name.git
# Update the repo's metadata
$ git fetch
# Actually get the changes to the files
# NOTE: `main` is the branch name
$ git pull main
Each repository update is packed into commits. A commit is a bundle of changes (additions or deletions).
Screenshot 2024-11-14 alle 11.13.47.png
Screenshot 2024-11-14 alle 11.15.18.png
- Author
- A hash that identifies the commit
- A commit message detailing what was done
- Additions and/or deletions
- Date and time of creation
- (Optional) signature verification
Commits operate on a file-level:
- You change some files
- You
git add
the files you want to put into your commit - You create the commit:
git commit -m <message>
- You the commit:
git push origin main
Each repository keeps a history of all of the changes happening, at a commit-level.
This means that you may skip back and forth between commits as you please.
$ git checkout <commit_hash>
This will bring your local copy to the specified commit.
If you want to revert the state of the repository back a couple commits, you can use git reset
:
- Find the commit you want to
reset
to:
$ git log --oneline
> e56ba1f (HEAD -> master) Revert "Just a regular update, definitely no accidents here..."
> 52418f7 Just a regular update, definitely no accidents here...
> 9a9add8 (origin/master) Added .gitignore
- Pick the commit you want as the last one (basically the last “good” commit):
9a9add8
- Reset to that commit
$ git reset 9a9add8
- Update the remote repository
$ git push --force
⚠️ WARNING! This will delete every commit after the one you picked.
Make sure nobody is working on those commits before nuking them like this!
$ git switch fix/something
To create the branch, if it doesn’t exist, add the -c
flag after git switch
, as follows:
git switch -c ...
Merging will create a commit that brings those changes into the desired branch.
- Move to the destination branch
$ git checkout main
- Merge the source branch
$ git merge fix/something
The Git Terminal should now guide you to write a message cor the merge commit.
- Delete the unnecessary source branch
$ git branch -d fix/something
- Push the merge commit
$ git push main