The Git version control system

By Jeetaditya Chatterjee

git commit -am "Totally a profesional developer"

Press s for speaker notes

What is version control?

  • Some features of Version control:
  • breaking code changes into revisions or “commits” each identifiable using a unique hash.
  • allowing for people to non destructively make copies of the code and merge them in when developed.
  • facilitating the ability to checkout and roll back commits throughout gits history
  • push the source code to a remote for backups and easy sharing of the source code.

Why use Version control? (git)

  • Breaking up code revisions into smaller chunks called “commits”
  • Allowing you to roll back commits for whatever reason
  • Allowing you to change your code base without affecting a master copy of your
  • Making it easier to collaborate and scale your code base to include more people

Some concepts

Starting off

init

$ git init

clone

$ git clone https://some.website/repo.git
# eg
$ git clone https://github.com/jeetelongname/example.git # you can actually clone this

status

git status

Staging

add

git add file

git add .

restore

git restore --staged file # removes file from the stage

git restore --staged . # removes all staged changes

git reset # also works

git config --global alias.unstage 'restore --staged'

git unstage file

Commits

commit

git commit # opens an editor where you type a message

git commit -a # commit all changes
git commit -m "commit message provided here"

Branches

branch

git branch <branch_name>

git branch <branch_name> <base_branch_name>


git branch -d <branch_name>

git branch -D <branch_name>

checkout

git checkout <branch_name> # switch to that branch

git checkout -b <new_branch_name>

Merging

merge

git checkout master
git merge feature # merge feature into master

git merge master feature # merge feature into master

rebase

git checkout feature
git rebase master # rebase master onto feature

git rebase feature master # samething but one line

Remotes

remote

git remote add <remote_name> https://your.url.here/repo.git

git remote add origin https://github.com/jeetelongname/example.git

git remote set-url origin https://git.sr.ht/~jeetelongnamr/example.git # not real

git remote rename orign upstream

git remote remove upstream

push

git push origin master
git push -u origin devel # pusing for the first time
git push origin master --force # overwrite the remote

fetch

git fetch origin # fetch all of the branches named origin
git fetch origin some-branch

git checkout some-branch

pull

git pull origin master # merges
git pull -r origin master # rebases

Reverting

log

revert

git revert b4e73eef1e7a1620... # full hash works

git revert b4e73 # also works

git revert HEAD~1 # roll back one commit

What do you do now?

Any Questions?