Skip to content

Mikma03/Git_GitHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version control - Git - test

Table of content

Courses provided by GitHub

GitHub docs

Git with VSC

Useful links

 

Introduction

This repository consist of usefull materials and shows workflow in version control using Git. Some materials also show how to use GitHub.

 

Materials

Book

YouTube course

 

Git interface (Git Bash/Git GUI)

git status

When we want to check status of files in our repositary we can use:

git status

git config

Settings for new user - add user e-mail:

 git config --global user.name "YOUR Name"

E-mal:

git config --global user.email "YOUR EMAIL"`

clear command

To clear our console just use:

clear

Basic Git flow could look like that:

git add FILE_NAME

git commit -m "your commnet for changes you've done"

git push

The git add command adds new or changed files in your working directory to the Git staging area. Git add is an important command - without it, no git commit would ever do anything. Sometimes, git add can have a reputation for being an unnecessary step in development. But in reality, git add is an important and powerful tool. git add allows you to shape history without changing how you work.

git add *

History of commits. Shows the commit logs.

git log

.gitignore

We tell git which files will be untracked. Also on GitHub there is a project which cosnsist of templates for gitignore in case of every language.

Flow how to add .gitignore file manually

10.1. Create the text file `gitignore.txt`.

10.2. Open it in a text editor and add your rules, then save and close.

10.3. Hold SHIFT, right click the folder you're in, then select Open `command` window here.

10.4. Then rename the file in the command line, with ren `gitignore.txt` `.gitignore`.

Branches

How can we check where we are in case of branch:

git branch

Create new branch:

git branch NAME_OF_NEW_BRANCH

When we want change branch

git checkout NAME_OF_BRANCH

When we want to make changes on our remotely repository and add new branch which is already exist on our local workspace:

git push -u origin NAME_OF_NEW_BRANCH

Create new brach and autamatillcy checkout branch:

git checkout -b NAME_OF_NEW_BRANCH

Graph of our changes in the console:

git log -oneline -graph -all

Git Stash

Add something to storage we can use command:

git stash

Check what is in our storage we should use:

git stash list
  1. Changes in our storage are indexed and we can acess to then by

 

stash@{X}

 

  1. We can add multipletimes changes and updates and everytime our list will be reindexed moreover the latest index is our last change and this is index{0}. If we want identify difference between stash commit we can use:

 

git stash show stash@{X}

where ```{X}``` is number of stash commit

 

  1. When our changes in storage are simillar or commend git stash show doesn't show the changes we are interested in then we can use:

 

git stash show stash@{X} -p

 

  1. In case when we change two or more files we can use

 

git stash save "Descriotion for our changes"

 

  1. When we want apply changes from storage to our file we can use below command, but in this case only the latest commit will be applied. Also in this case changes are still in storage.

 

git stash apply

 

  1. When we want delete changes from storage after adding those to file we can use:

 

git stash pop

 

  1. In case when we want apply changes from choosen commit we can use:

 

git stash pop stash@{X}

 

  1. When we want delete stash commits form storage we can use

 

git stash drop stash@{X}

 

or when we want everything what is inside of storage

 

git stash clear

 

  1. When we want to add new file but that file is untracked by git but we need to add changes in this file to storage then

 

git stash -u

 

or

 

git stash -a

 

  1. If we want create new branch for stash commit we should use

 

git stash branch NAME_OF_NEW_BRANCH stash{0}

 

  1. Changes made by git stash can be moved to another branch

 

git stash pop

 

Merge conflict

 

If cinflict appear in out git flow we need to select which part of code we want in our file. When conflict appera and after taht we select code we need to one again to throught git flow:

 

  1. git add

 

  1. git commit

 

  1. git push

 

Git Revert and Git reset

 

  1. When we want to go back to a selected point in the past on our time line we can do this with:

 

git checkout COMMIT_ID

 

  1. In case when we want restore changes form selected commit

 

git revert COMMIT_ID

 

  1. History of commits

 

git log --oneline

 

  1. To reset old commits we can use

 

git reset COMMIT_ID

 

  1. There are two possible reset posibillity

 

git reset COMMIT_ID --soft

 

or

 

git reset COMMIT_ID --hard

 

How to change names of commits

 

  1. When we want change commit we can use

 

git commit --amend -m "message update"

 

  1. To display information about one commit we should use

 

git show COMMIT_ID

 

  1. In case when we want change more than one commit we can use

 

git rebase -i HEAD~X p = pick r = reward

 

Fork and Pull Request

 

 

  1. To Fork another repositary from someone GitHub we need go there and choose "fork" then probably we want to clone that repositary to our local workspace.

 

git clone PASTE_URL_HERE

 

  1. How to go into the project

 

cd PROJECTNAME/

 

Git history

 

  1. To check Git history we should use:

 

git log

 

or for example three last commits

 

git log --onelone -3

 

or when we want to see selected authon

 

git log --author=AUTHOR_ID

 

or we can select specyfic dates parameters:

 

git log --before "rrrr-mm-dd"

 

  1. Titles of commits

 

git log --oneline

 

git log --graph

 

git log --oneline --graph

 

git log --pretty="%H - %aN - %aD"

 

  1. Reflog - local history

 

git reflog -NUMBER OD COMMITS

 

Pull request

 

 

  1. New branch

 

git checkout -b BRANCH_NAME

 

to send new branch to remotely repo we can use:

 

git commit -a -m "message"

 

Next

 

git push --set-upstream origin BRANCH_NAME

 

Git rebase & git merge

 

 

Git squash

 

 

git rebase -i COMMIT_ID

 

and next we need to select -s squash

 

Git cherry-pick

 

 

git cherry-pick COMMIT_ID

 

Tagging

 

 

  1. Example

 

git tag TAG_NAME COMMIT_ID

 

  1. release all tags

 

git push --tags

 

  1. Delete tags

 

3.1. Local

 

git tag -d TAG_NAME

 

3.2. Remote

 

git push -d origin TAG_NAME

 

Releases

No releases published

Packages

No packages published