Ultra gitbranch note PART 1/2 Local

What’s GIT?

It’s the most popular version control system (and I finally understand what it means).

What’s GIT for?

It records changes made to our code over time in a special data base - REPOSITORY. It also give as an opportunity to work with someone else on the same project in the same time.

In favour of that we can look at our project history and see who and when made which changes. What’s more, we can always go back to a previous stage of our project if something further got ducked up.

What’s GIT branching and merging?

Those are actions letting us create and unite developed copies of our project. There are many commands that help with doing branching and merging stuff.

I don’t know how writing in git looks like in practise, but I will ask my mentor tommorow :)

Names and commands (commands are in italics)

Commit - it records (in repository) snapshots of all files in my catalog. It’s smart technology, so it doesn’t copy all files round and round, but sometimes compresses commit as a set of changes.

git commit - creates a commit, when we make some changes

Branch - it just point to specific commit.

,,Branch says: I want to incorporate work of this commit and all previous ones."

git branch (name) - creates new branch

git checkout (name) - points on specific branch before making changes.

git checkout -b (name) - creates new branch and automatically switches on it

git merge (name of commit you wanna merge with) - combines two commits into one and gets all of the work made in parent commits

git rebase (name) - works almost like merging, but it creates a copy under rebasing commit and doesn’t make two in one like merging. I don’t know if it has sense for someone reading this, but I get it :D

HEAD - currently pulled commit, actually commit with newest changes

git checkout (commit hash) - disconnects HEAD from branch and connects to a specific commit

git checkout (name or HEAD)^ - moves HEAD to the parent of chosen commit

git checkout (name or HEAD)~(number) - moves HEAD (number) steps back

git branch -f (branch name) (name or HEAD)~(number) - forcing chosen branch to move (number) steps back

git reset HEAD~(number) - now our local repository looks like reseted commit never existed

git revert HEAD - it changes our previous changes so now we don’t have first changes :))))) It’s like git reset, but works also for online branches, not just local.

git cherry-pick (commit)(commit)(…) - moves our work from different commits to the main branch

git rebase -i HEAD~(number) - when you don’t know which commits you wanna ,,cherry-pick" you can always open interactive panel with this command and move work to specific commit pointed by HEAD~(number)

tag - anchor for commit. Works like branch, but is immovable and you can’t update it, you can just go back to it if it’s necesery. It has its own name.

git tag (name) (commit[if not, HEAD]) - gives a named tag to a specific commit

git describe - helps us getting know our location on the repository tree. Shows the closest tags and a commit we are on ex.: v1_2_gC6

Another way to navigate the tree

git checkout HEAD~^2~2

And the part ,,^2" lets us choose a way through another parent, not that straight above us