Laboratorio di Ingegneria del Software 2 - Anno accademico 2020-2021 - Università degli studi di Trento
- Git CLI (https://git-scm.com/downloads)
- GitHub (https://github.com), con l'indirizzo @unitn si ottiene la licenza pro
- Guida a git (https://www.atlassian.com/git/tutorials)
https://www.atlassian.com/git/tutorials/setting-up-a-repository
-
Initialize a new repository in a local directory
git init -
Configure git
git config --global user.name "<your name>"git config --global user.email <your email>git config credential.username <your username> -
Check status
git status -
Stage files (tracked and untracked)
git add . -
Commit staged changes
(-m: add message)
(-a: stage changed tracked files, but in case you have new files you need to dogit add .to manually track them )
(In Vim pressEscand then type:qto quit;:wto save;:xto save and exit)git commit -m "first commit" -
Include staged changes in last commit
git commit -amend -
Check differences
git diff master^^ index.js(check with 3 REPO commits ago)git diff <hash> index.js -
Check commits history
git log --oneline -
Revert back your working directory to a previous commit
git checkout <commit ID>git checkout master
https://www.atlassian.com/git/tutorials/using-branches
-
Modify files then create a new branch, stage and commit changes, and push to remote repository
git branch newFunctiongit checkout newFunctionAlternatively:
git checkout -b newFunctiongit commit -am "commit in the new branch"git log -
Delete a branch
git branch -d newFunction -
Fast-forward merge
https://www.atlassian.com/git/tutorials/using-branches/git-merge
git checkout mastergit merge newFunctiongit log --graph --decorate --oneline -
Resolving conflicts in 3-way merge
https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts
git mergetool
https://www.atlassian.com/git/tutorials/using-branches/merge-strategy
https://www.atlassian.com/git/tutorials/syncing
-
On github.com create a github repository
-
Clone repository in a local directory
git clone [repoAddress] [folderName] -
Check differences with remote repository
git diff origin master index.js -
Delete remote branch
git branch -d [branch_name](delete local branch)git push origin -d [branch_name]git push origin :[branch_name] -
Git remote
git remote -vgit remote add <name> <url> -
Pull changes
https://www.atlassian.com/git/tutorials/syncing/git-pull
git pull -
Fetching changes without merging
https://www.atlassian.com/git/tutorials/syncing/git-fetch
git fetch origin mastergit branch -a -
Push changes to remote repository
https://www.atlassian.com/git/tutorials/syncing/git-push
git push origin master
-
Stashing changes before applying
git stashgit stash pop -
Rebasing
https://www.atlassian.com/git/tutorials/merging-vs-rebasing
git rebase master(commits in current branch are "re-applied" to the head of master)git rebase -i master -
Tagging
git tag v1.0git tag -a v1.0 -m "my version 1.0"git tag -
Reset
https://www.atlassian.com/git/tutorials/undoing-changes https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
- --soft – The staged snapshot and working directory are not altered in any way.
- --mixed – The staged snapshot is updated to match the specified commit, but the working directory is not affected. This is the default option.
- --hard – The staged snapshot and the working directory are both updated to match the specified commit.
git reset HEAD <file>...git reset HEAD~2 -
Revert
git revert -
Check with gitk
gitk
https://www.atlassian.com/git/tutorials/comparing-workflows#centralized-workflow
In this flow, the default development branch is called master and all changes are committed into this branch. This workflow doesn’t require any other branches besides master.
Tip:
git pull --rebase origin master
The pull would still work if you forgot this option, but you would wind up with a superfluous “merge commit” every time someone needed to synchronize with the central repository. For this workflow, it’s always better to rebase instead of generating a merge commit.
https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow
The core idea behind the Feature Branch Workflow is that all feature development should take place in a dedicated branch instead of the master branch. This encapsulation makes it easy for multiple developers to work on a particular feature without disturbing the main codebase. It also means the master branch will never contain broken code, which is a huge advantage for continuous integration environments.
https://www.atlassian.com/git/tutorials/making-a-pull-request
https://www.atlassian.com/git/tutorials/comparing-workflows
The Gitflow Workflow defines a strict branching model designed around the project release. This provides a robust framework for managing larger projects.
This workflow doesn’t add any new concepts or commands beyond what’s required for the Feature Branch Workflow. Instead, it assigns very specific roles to different branches and defines how and when they should interact. In addition to feature branches, it uses individual branches for preparing, maintaining, and recording releases.
The master branch stores the official release history, and the develop branch serves as an integration branch for features. It's also convenient to tag all commits in the master branch with a version number.
Features should never interact directly with master.
Once develop has acquired enough features for a release (or a predetermined release date is approaching), you fork a release branch off of develop. Creating this branch starts the next release cycle, so no new features can be added after this point—only bug fixes, documentation generation, and other release-oriented tasks should go in this branch. Once it's ready to ship, the release branch gets merged into master and tagged with a version number. In addition, it should be merged back into develop, which may have progressed since the release was initiated.
Maintenance or “hotfix” branches are used to quickly patch production releases.
https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
As in the other Git workflows, the Forking Workflow begins with an official public repository stored on a server. But when a new developer wants to start working on the project, they do not directly clone the official repository. Instead, they fork the official repository to create a copy of it on the server.
It's important to note that "forked" repositories and "forking" are not special git operations. Forked repositories are created using the standard git clone command. Forked repositories are generally "server-side clones" and usually managed and hosted by a 3rd party Git service.











