Learning Node #1 - A Crash Course in Git
A Crash Course in Git
Welcome to the Git Learning Node! Here is the documentation for all of the normal operations that we primarily use on a day to day basis in the industry.
Here is the definition of Git directly from git-scm:
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.
Basic Git Commands
For each of the below commands, run the following in your terminal to get to know a bit more about the command. These commands are the bread and butter for using git for normal operations:
git COMMAND --help
- git clone
- git checkout
- git pull
- git status
- git diff
- git add
- git rm
- git commit
- git push
- git log
Intermediate Git Commands
For each of the below commands, run the following in your terminal to get to know a bit more about the command. These commands are more advanced in use and are used in one off cases more so than normal day to day operations:
git COMMAND --help
- git stash
- git fetch
- git remote
- git merge
- git rebase
- git log (options)
- --oneline --graph --all --decorate=full
- git cherry-pick
- git reset
- git branch
- git blame
Rebase vs Merge
As part of the Atlassian Gitflow, we have adopted the rebase pattern over the merge pattern for bringing changes into the baseline. This is an opinionated approach to our gitflow, but we have found that this helps us in the following ways:
- We no longer have merge commits throughout our git history, which are empty commits that dictate a merge has occurred.
- With rebasing frequently, we only ever ‘Fast-Forward’ when a merge occurs, meaning that there are no merge commits.
- We no longer need to merge master back into our feature branches. This can cause odd looking git graphs/history and can lead to odd merge conflicts and resolution.
- With rebasing, we are able to resolve conflicts through editing history. Since feature branches are meant to be ephemeral and not long standing, this fits the model. The major downside is the risk of lost work, but with time, patience, and mastery of frequent rebasing and conflict resolution, conflicts should no longer be long, convoluted processes that are error prone.
- Less commits overall becomes easier to read the git history.
For more information on Rebasing, please check out the following tutorial: Git-Branching-Rebasing.
Normal Git Workflows
I’m new to the project! How do I set up for the first time?
git clone SSH_REPO git checkout -b TG-###_ShortDescription // Complete ticket/work assigned git add *Files* git commit -m “Helpful commit message.” git push -u origin *Branch Name*
Workflow Diagram: Cloning a Repository
Workflow Diagram: Submitting Work to the Remote Repository
How to update your local master branch
I have the repository locally already, but I know there are new changes on master that I need. How do I retrieve those new changes?
- You are on your local branch
git checkout master git pull
How to rebase your local branch onto your local master branch
I have a local branch or some local changes already, but I’m not done, AND I need some new changes in master in order to complete my work. How can I setup my local repository with the new changes and my local changes on my branch? For more information on Rebasing, please check out the following tutorial: Git-Branching-Rebasing.
- You are on your local branch
// Optional, if you have local UNTRACKED changes, you will need this git stash git checkout master git pull git checkout *Branch Name* git rebase master git push --force-with-lease
Help! I don’t know where I am!
// See what your local branch and changes are git status git status -b // See your current history in normal log or graph form git log git log --oneline --decorate=full --graph --all // See what your local changes are git diff // See what your changes are from the master branch git diff master
As part of the Incubator experience, we have created a set of exercises to help you learn and use git on your own. Ask your mentor for more information. You can access the git repository here: https://gogs.caifos.us/Sofiac/git-learning-node.
Extensions and Resources
- Git Home
- Git Documentation
- Git Interactive Cheat-sheet
- Clean up your Mess
- Atlassian Gitflow
- Rebase vs Merge
Exerceo welcomes feedback! Improving the community of rising professionals is a team sport. Please join our team by sharing your success stories and constructive criticism to both inspire and improve our programs for everyone. Please send all feedback to email@example.com
Exerceo's goal is to provide guidelines to rising professionals; however, everyone's situation can vary greatly so please apply your own judgment and best practices.
Attend Learning Node
Are you ready to take your career to the next level? Do you want to meet a group of like-minded hardworking individuals? Give yourself a jump start by joining one of our free programs.Enroll Now
Exerceo exists to lead and inspire others to transform society by extending relevant learning and mentorship into everyday lifestyle.