- Version control - Git - test
- Table of content
- Courses provided by GitHub
- Git with VSC
- Useful links
- Introduction
- Materials
- Git interface (Git Bash/Git GUI)
- Branches
- Git Stash
- Merge conflict
- Git Revert and Git reset
- How to change names of commits
- Fork and Pull Request
- Git history
- Pull request
- Git rebase & git merge
- Git squash
- Git cherry-pick
- Tagging
-
Intro to VSC and GIT
-
Branches in VSC
-
TOP 6 Git extensions
-
Branches, merge, clone, fork
-
Add Image to GitHub Readme.md from Google Drive
Example how to connect to image from Google Drive:
<p align="center"> <img src="https://drive.google.com/uc?export=view&id=15RSv1aY_71BH8cekrD8fihYPDXeS0OFT" /> </p>
-
When local branch and remote branch are differen and you want work on one branch - one of my issue with Git
-
Gitignore files templates
This repository consist of usefull materials and shows workflow in version control using Git. Some materials also show how to use GitHub.
- Book which cover most informations about GIT
- Git course (for native Polish speaker or those who like subtitles)
When we want to check status of files in our repositary we can use:
git status
Settings for new user - add user e-mail:
git config --global user.name "YOUR Name"
E-mal:
git config --global user.email "YOUR EMAIL"`
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
- More info about
git logs
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.
-
Commends for .gitignoge
-
A collection of .gitignore templates
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`.
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
Add something to storage we can use command:
git stash
Check what is in our storage we should use:
git stash list
- Changes in our storage are indexed and we can acess to then by
stash@{X}
- 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
- 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
- In case when we change two or more files we can use
git stash save "Descriotion for our changes"
- 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
- When we want delete changes from storage after adding those to file we can use:
git stash pop
- In case when we want apply changes from choosen commit we can use:
git stash pop stash@{X}
- 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
- 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
- If we want create new branch for stash commit we should use
git stash branch NAME_OF_NEW_BRANCH stash{0}
- Changes made by git stash can be moved to another branch
git stash pop
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:
git add
git commit
git push
- 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
- In case when we want restore changes form selected commit
git revert COMMIT_ID
- History of commits
git log --oneline
- To reset old commits we can use
git reset COMMIT_ID
- There are two possible reset posibillity
git reset COMMIT_ID --soft
or
git reset COMMIT_ID --hard
- When we want change commit we can use
git commit --amend -m "message update"
- To display information about one commit we should use
git show COMMIT_ID
- In case when we want change more than one commit we can use
git rebase -i HEAD~X
p = pick r = reward
- 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
- How to go into the project
cd PROJECTNAME/
- 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"
- Titles of commits
git log --oneline
git log --graph
git log --oneline --graph
git log --pretty="%H - %aN - %aD"
- Reflog - local history
git reflog -NUMBER OD COMMITS
- 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 -i COMMIT_ID
and next we need to select -s squash
git cherry-pick COMMIT_ID
- Example
git tag TAG_NAME COMMIT_ID
- release all tags
git push --tags
- Delete tags
3.1. Local
git tag -d TAG_NAME
3.2. Remote
git push -d origin TAG_NAME