weekly-coordination
December 19, 2022
Git & GitHub
Are you ready to jump into the world of VCS?
That's awesome. Let's do that together!
Basic background
Version control is a system that records changes to a file or set of files over time so that we can recall specific versions later.
3 types of VCS's
⬇️ ⬇️ ⬇️ ⬇️
Dive into Git & GitHub
Distributed VCS is the real power. We can see that by just looking at Git.
Git Features
- Distribution
- Size and Speed
- Data Assurance
- Open Source
- Branching and Merging
- Detailed information about them - https://git-scm.com/about
Git installation
Git download page - https://git-scm.com/downloads
- Windows: https://git-scm.com/download/win
- MacOS:
brew install git
- Ubuntu:
sudo apt-get install git-all
Configuration
Template: git config --global <key> <value> -> git config --global user.name "Your Name" -> git config --global user.email [email protected]
File States
Commits & Branches
*HEAD is one of the pointers. For every branch, there's a *HEAD pointing to the last commit.
Commit
-> git add <filename> -> git commit -m "a clear message"
Git add
Add changes in working directory to the staging area: -> git add <filename> [<filename>] A command that accepts wildcards as parameters: -> git add *.py A dot ‘.’shortcut is used to add all files: -> git add . For tracking current changes, use: -> git status
It is not recommended to do thegit add .
andgit add -A
for not adding unnecessary files.
.gitignore
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected. Each line in a gitignore file specifies a pattern. Detailed explanation: https://git-scm.com/docs/gitignore
Git commit
“git commit” is used to commit the staged files to the repo. The default file editor will be opened to allow you to add commit message: -> git commit Use -m parameter to add inline commit message instead: -> git commit -m “first commit” Add staged changes to the last commit: -> commit --amend
In the process of usingcommit --amend
, we can also change the message of the commit. To avoid that, we can use a flag--no-edit
Branches
View the list of existing branches: -> git branch Create a new branch: -> git branch feature
Switch to the branch: -> git checkout feature Short alias to create new branch and switch to it: -> git checkout -b feature
Merging
Just imagine you have the repository represented, and you need to have your feature
in the master branch.
We can usegit merge
command.
Git creates a new snapshot and automatically creates a new commit that points to it. This is called as a merge commit and it has more than one parent
-> git merge feature
Rebasing
It is the process of moving the base of our branch from one commit to another making it appear as if we had created our branch from a different commit.
-> git rebase master
It is a powerful feature. But, there could be some issues related to commits, so make sure that only you are working on one branch.
How to get a repository?
Create a new repo: -> git init Get an existing repo: -> git clone https://github.com/username/repo
Default name for remote repo is origin
Push & Pull (changes from the server)
To update remote refs using local refs and simply push changes to remote repo: -> git push
To take changes from remote repo and try to merge them to our local one: -> git pull It also works like a combination of merge and fetch commands for our local changes.
Commit History & File Changes
To show full commit history: -> git log To list all comments which were made from <commit 1> to <commit 2> (<commit 1> is not included): -> git log <commit 1>..<commit 2> To show differences between files in two commits or between our current repo and a previous commit: -> git diff
It is not easy to grasp that much details at first, but that doesn't mean it's impossible. It happens with almost everybody. Those who have found a special key can learn everything, and that key is consistency, my friend 😎
Thank you for your time with us. Keep learning and winning 🚀
Need more?
- What is version control? (atlassian) - https://www.atlassian.com/git/tutorials/what-is-version-control
- SSH generation - https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
- Git branching interactive tutorial - https://learngitbranching.js.org/
- Pro Git book - https://git-scm.com/book/en/v2
- Comparing Git Workflows: What You Should Know (atlassian) - https://www.atlassian.com/git/tutorials/comparing-workflows
Video materials 📺
- Git Tutorial for Beginners: Command-Line Fundamentals (Corey Schafer) - https://www.youtube.com/watch?v=HVsySz-h9r4&list=PL-osiE80TeTuRUfjRe54Eea17-YfnOOAx
- Getting started with Git & GitHub (Start your own projects!) (Caleb Curry) - https://www.youtube.com/watch?v=SExhUmE7OLA&t=1s
- Git + GitHub Branches, Forks, and Pull Requests (Caleb Curry) - https://www.youtube.com/watch?v=oa1wXWeH1IQ&t=339s