Creating a New Commit ▪ A commit is created from the changes to one or more files on disk. ▪ Git allows files to be added incrementally to the stage area. 13 echo “print ‘hello world’” > test.py git status
Removing a File rm --cached 19 git rm --cached trash.py git status touch thrash.py git add trash.py && git status ▪ Removes the file from version control but preserves the file locally
LET’S REVIEW SOME COMMANDS git init Creates a new local repository. git add Snapshots the file in preparation for versioning. git commit Records file snapshots permanently in version history. git log Lists version history for a file. git rm --cached Removes the file from version control but preserves the file locally. git status Lists all new or modified files to be committed. 21
Upload Commits 24 git push -u ▪ Pushing is how you transfer commits from your local repository to a remote repository git remote -v git push -u origin master git status git status
LET’S REVIEW SOME COMMANDS git push Uploads all local commits to the remote server. git fetch Downloads all history from the repository bookmark git pull Downloads bookmark history and incorporates changes 27
Create a New Branch branch 31 ▪ A branch represents an independent line of development. ▪ A branch is a pointer to a commit. git checkout -b git branch git branch -a https://www.atlassian.com/git/tutorials/using-branches
Delete a Branch branch 32 git branch -d ▪ Once you’ve finished working on a branch and have merged it into the main code base, you’re free to delete the branch without losing any history. git push origin --delete git branch -D https://www.atlassian.com/git/tutorials/using-branches
Switching between Branches checkout 33 ▪ This command lets you navigate between the branches. * Atlassian Bitbucket. Resetting, Checking Out & Reverting. Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting git checkout
Merging Branches merge 34 ▪ It takes a sequence of commits of a branch and integrate them into a another one. ▪ It creates a new “merge commit” ▪ It is a non-destructive operation * https://www.atlassian.com/git/tutorials/using-branches/git-merge git merge
Temporarily Stashing Some Changes stash 36 git stash ▪ It temporarily shelves changes (staged/tracked) that can be reapplied later on. ▪ Useful when you need to quickly switch context and work on something else. git stash apply git stash list git stash pop git stash drop * https://www.atlassian.com/git/tutorials/saving-changes/git-stash
LET’S REVIEW SOME COMMANDS git branch Creates, deletes and lists branches. git checkout Switch branches or restore working tree files. git merge Incorporates changes from a branch into the current branch. git clean Removes untracked files from the working tree. git stash Stashes the changes in a dirty working directory away. 37
Rebase a Branch rebase 40 ▪ Re-writes the project history by creating brand new commits for each commit in the original branch ▪ Trade-offs: safety and traceability ▪ Golden Rule: never use rebase on public branches * Atlassian Bitbucket. Merging vs. Rebasing. url: https://www.atlassian.com/git/tutorials/merging-vs-rebasing
Reset to a Previous Commit reset 41 ▪ Versatile tool for undoing changes. ▪ Forms of invocation: --soft, --mixed, --hard ▪ It moves both the HEAD and branch refs to a specific commit. * Atlassian Bitbucket. Resetting, Checking Out & Reverting. Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
Reset to a Previous Commit reset 42 ▪ Versatile tool for undoing changes. ▪ Forms of invocation: --soft, --mixed, --hard ▪ It moves both the HEAD and branch refs to a specific commit. * Atlassian Bitbucket. Resetting, Checking Out & Reverting. Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
Revert a Previous Commit revert 43 ▪ Revert a commit that made changes you want to undo. ▪ Reverting undoes a commit by creating a new commit. ▪ It is a “safe” way to undo changes * Atlassian Bitbucket. Resetting, Checking Out & Reverting. Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
LET’S REVIEW SOME COMMANDS git rebase Re-applies commits on top of another base tip. git reset Resets current HEAD to a specific state. git revert Reverts some existing commits. 44
CREDITS Special thanks to all the people who made and released these awesome resources for free: ▪ Presentation template by SlidesCarnival ▪ Photographs by Unsplash ▪ Stickers by Telegram 46