$cdprojects#your path$pwd# 1. Clone project from GitHub$gitclonehttps://github.com/testerBartek/GIT$cdGIT$gitstatus# 2. Create test.txt with wrote Test Git$echo"Test Git">>test.txt$ls$cattest.txt$gitstatus# 3. Add, Commit with message$gitaddtest.txt$gitstatus$gitcommit-m"Add a test.txt file"$gitstatus# 4. Push to remote Repo (GitHub)$gitpushoriginmaster
Init (Fresh Project), use alias notepad++, remove
$cdprojects$ls# 1. init Fresh Project$gitinitgitFromLocalRepo$ls$cdgitFromLocalRepo# 2. Looking on hidden folder .git$ls-al$cd.git/$ls$gitstatus# 3. Create a new .txt file using alias with notepad++ (npp)$npptestLocalRepo.txt#notepad++ should be openned, and write sth, save, and exit$ls#.txt file is created$gitstatus#untracked file testLocalRepo$gitaddtestLocalRepo.txt$gitstatus# changes to be comitted$gitcommit-m"Create a new Remote Repo from Local Repo"$gitstatus#nothing to commit, working tree clean$cd..$ls# 4. Force remove whole folder testLocalRepo$rm-rftestLocalRepo$ls#repo is removed.
Unzip and mv of dir, remote GitHub
#by using website http://www.initializr.com/ download a data to a new repository#download it :)$cdprojects# 1. unzip directory$unzip~/Downloads/initializr-verekia-4.0.zip#folder unzipped in our path$ls#name of directory is initializr# 2. change name of directory$mvinitializrrepoExistingProject#mv CURRENT_NAME_OF_DIR FUTURE_NAME_OF_DIR$ls#check name - now is repoExistingProject$cdrepoExistingProject$ls# 3. init empty Git repo of existing project$gitinit#Initialized empty Git repository in #C:/Users/nn/projects/repoExistingProject/.git/$gitstatus#a lot of untracked files$gitadd.#Adding whole untracked files to Staging Area$gitstatus#All files are added as new file.$gitcommit-m"Creating first git repo from Existing project"$gitstatus#On branch master \n nothing to commit, working tree clean# 4. Push existing repo to remote repo (GitHub)# Firstly we need to create new repository on our github: $gitremoteaddoriginhttps://github.com/testerBartek/repoExistingProject$gitremote-v#check is it corectly added#origin https://github.com/testerBartek/repoExistingProject (fetch)#origin https://github.com/testerBartek/repoExistingProject (push)$gitpushoriginmaster
The basic commands
$mkdirNAME_OF_DIRECTORY#Making a new folder from git bash.$mkdir-pfolder1/folder2/folder3#Making a new folders in given path folder1/folder2/folder3
$cdNAME_OF_DIRECTORY$cd..#Changing current directory
$pwd#Checking current path.
$ls$ls-al#show files in hidden directory .git#list all folders and files in our current path.
$echo"Test Git">>test.txt#Create a notepad file "test.txt" where is wrote Test Git.$cattest.txt#Show in git bash what is wrote in this file.
$clear#clear console$exit#exit console
Setup and Config
git
$gitversion#checking installed version of git$gitupdate-git-for-windows#download and update the newest version of git
git config
$gitconfig--globaluser.name"Bartek SzelÄ…g"$gitconfig--globaluser.email"tester.bszelag@gmail.com"#adding user with name and email address to global in git.$gitconfig--global--list#show list of global data$npp~/.gitconfig$notepad++~/.gitconfig#edit .gitconfig file with notepad++
Getting and Creating Projects
git init
$gitinitgitFromLocalRepo#name of new repo#initialized empty Git repository in C:/Users/nn/projects/gitFromLocalRepo/.git/#in current path was created a new folder with hide files name .git
git clone
$gitclonehttps://github.com/testerBartek/GIT#full copy of our repository Github on our system.
Copy will be create in our current path ($ pwd)
Basic Snapshotting
git add
$gitaddtest.txt$gitadd.#adding untracked files to git. [To Staging Area]$gitadd-A#if we changed the name of file without git.#1st file is deleted and 2nd file is added.#by using add -A the same files are changed on renamed.
With dot "." adding all the untracked files.
git status
$gitstatus#Changes about git status only are visible when you add, #delete or modify your documents which is in .git
On start of learning use this command very often.
git restore
###delete changes from workind directory#### make any change in file$gitstatus#Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git restore <file>..." to discard changes in working directory)# modified: humans.txt$gitrestorehumans.txt#to check$gitstatus#nothing to commit, working tree clean$gitrestore--stagedhumans.txt#doing the same thing like git reset
git reset
###changes from staging area > working directory###$gitaddhumans.txt$gitstatus#Changes to be committed:# (use "git restore --staged <file>..." to unstage)# modified: humans.txt#if file is added to Staging Area$gitreset#Unstaged changes after reset:#M humans.txt#back file to untracked to working directory#2.$gitrmhumans.txt$gitstatus$gitreset
git commit
$gitcommit-m"TYPE_YOUR_MESSAGE"#commit all changes with message in quote. [To Local Repository]$gitcommit-am"TYPE_YOUR_MESSAGE"#adding a untracked files and after that commit
git rm
$gitrmhumans.txt#Changes to be committed:# (use "git restore --staged <file>..." to unstage)# deleted: humans.txt$gitrm-rfNAME_OF_DIRECTORY# -f force # -f r directory name#Force remove everything from given name of folder #(whole with hidden folder .git too)
git mv
$gitmvcss/abc/#Renamed folder changes paths of every files in this directory.$gitmvhumans.txttest.txt#[current_name feature_name]#Change name of files.
Remember to use git mv not only mv. If we don't use it files wouldn't be renamed. They are deleted and add new one. After that use git add -A to repair it.
Branching and Merging
git log
$gitlog#show number of commit, author, date, and message$gitlog--test.txt#[file name] show only commites on specific file#commit f7530d23c2cd43a84954146269bca03b56bcd20b #(HEAD -> master, origin/master, origin/HEAD)#Author: Bartek <tester.bszelag@gmail.com>#Date: Mon Aug 10 08:35:02 2020 +0200# Test git log (history)##commit 5a7ea8258abbd4338ec274d5f010d5117d95c9f0#Author: Bartek <tester.bszelag@gmail.com>#Date: Sun Aug 9 20:44:12 2020 +0200# Add some text to look on difftool$gitlog--abbrev-commit#show the same informations but commit number shorten to 7 characters#it's easier to use commit number to another actions of logs.#commit f7530d2 (HEAD -> master, origin/master, origin/HEAD)#Author: Bartek <tester.bszelag@gmail.com>#Date: Mon Aug 10 08:35:02 2020 +0200# Test git log (history)$gitlog--oneline--graph#--oneline# show 7 characters of commit number (like using --abbrev-commit)# commit message# --graph# show way of commites* 84cc8c1 Add text to file* 96e899e Commit branch to master* e858bc6 Merge branch 'master' of https://github.com/testerBartek/GIT|\ #--graph command|*8244870UpdateREADME.md*|1e640f4Deletingtext,emptyfilecommit|/#--graph command* 8c51967 Checking some changes$gitlog--since="3 days ago"#the same command like git log (but only show period time)$gitshowf7530d2#commit f7530d23c2cd43a84954146269bca03b56bcd20b #(HEAD -> master, origin/master, origin/HEAD)#Author: Bartek <tester.bszelag@gmail.com>#Date: Mon Aug 10 08:35:02 2020 +0200# Test git log (history)##diff --git a/test.txt b/test.txt#index 085cb08..c17c4b0 100644#--- a/test.txt#+++ b/test.txt#@@ -2,4 +2,5 @@ Test Git# 2# 3# 4#+Test git log (history)# 5
Check for modifications and copy it from remote Repository.
#1. change any file on the website e.g. #https://github.com/testerBartek/repoExistingProject$gitpulloriginmaster#check to any change from github#remote: Enumerating objects: 5, done.#remote: Counting objects: 100% (5/5), done.#remote: Compressing objects: 100% (3/3), done.#remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0#Unpacking objects: 100% (3/3), 774 bytes | 32.00 KiB/s, done.#From https://github.com/testerBartek/repoExistingProject# * branch master -> FETCH_HEAD# 77b3204..9dd2a4c master -> origin/master#Updating 77b3204..9dd2a4c#Fast-forward# README.md | 2 ++# 1 file changed, 2 insertions(+)#If local Repo is up to date it will show$gitpulloriginmaster#From https://github.com/testerBartek/repoExistingProject# * branch master -> FETCH_HEAD#Already up to date.
git push
$gitpushoriginmaster#Local changes are push to remote GitHub and on website changes are made.#origin - GitHub copy of our repository#master - master branch
git remote
Add existing local repository to GitHub remote repository.
$gitremoteaddoriginhttps://github.com/testerBartek/repoExistingProject# Sets the new remote by remote repository URL from GitHub $gitremote-v# Verifies the new remote URL#> origin https://github.com/testerBartek/repoExistingProject (fetch)#> origin https://github.com/testerBartek/repoExistingProject (push)
Guides
gitignore
#1. create file .gitignore$npp.gitignore#2. add files which we want ignore (no commit)#in single line#specific file: file.xyz#file pattern: *.xyz#folder: xyz_folder/#3. add and commit .gitignore file
something in .gitignore file will never be commited
Plumbing Commands
git ls-files
$gitls-files#list a tracked files
Git programs integrations
Environment variable
Copy path of file .exe of your program
Open Advanced system settings
Advanced
Environment Variables
Find Path in system variables and Click Edit...
Add new path like (C:\Program Files\Notepad++)
Adding alias
Alias to git bash
Path to Your user like
$ pwd
/c/Users/nn
Use command $ notepad++ .bash_profile
$notepad++.bash_profile
3. In new line just type an alias like You want.
For example to open "notepad++" don't type whole name just type or "npp".
alias npp='notepad++.exe -multiInst -nosession'
4. Save and close notepad++. Close and open again git bash.
5. Now after type $ npp should open notepad++
Alias to .git projects
alias to git log --all --graph --decorate --oneline"
$gitconfig--globalalias.hist"log --all --graph --decorate --oneline"# to use it in git bash$githist
Notepad++
Generally remember to close notepad++ and back to git bash.
Add notepad++ to environment variable
After that notepad++ could be run from git bash
$notepad++
3. You could add alias to create shortcut to open notepad++ like in Adding alias Heading.