New TitleChange&New TitleOtherChange
Title
git clone
git commit
New addition
git diff HEAD~1
git log
git restore --source hash file
-restore the version of the file corresponding to the state with the hash
TITLE2
git remote add origin url, define the link to a space with the name 'origin' with url
git pull
Closing
- git branch create a branch
- git branch rm remove branch
- git switch (-c) move to branch (and create it on the fly)
- git merge merge the current with
- Can be automatically combined
- git rebase to call from the branch to be rebased
- git status to know what to do during merge or rebase
- git rebase --continue after fixing conflicts
- git add after fixing conflicts in the code
- git rebase -i HASH or HEAD~4 to go interactive mode with squash or s to squash commit into previous one
- git stash instead of git commit to store changes without commit and change branch safely
- stash is temporary
- git stash apply to recover the last backup on a given branch
- git stash clear to clear the stashes
- A merge on the remote is called a pull request or merge request
- To update a PR, do changes locally and re push to the remote
- A merge conflict can happen after a PR is issued
- git fetch update git log
-git fetch --prune to prune branches inexisting on the remote
- git push -f to force the push
-git push --force-with-lease to push more carefully and not erase
Collaborators
- Second one to push need to sync their local with the remote repo
- git push --force-with-lease to push more carefully and not erase
- Add a collaborator in the settings of the repo
- The collaborator use git clone to get a copy of the remote on its local machine
- Each person's branch changes are independent from others
- Feature branches won't show any conflicts until you try to merge them
- You can setup branch protection rules to protect main branch from being directly pushed into
Git Workflow
- You can use dev flow
- Forking Workflow
- Fork is commonly used in massive open-source project
- Copy the original remote to get your own to work on without modifying the original
- origin is your remote and upstream is the original remote