Skip to content

Latest commit

 

History

History
220 lines (199 loc) · 4.59 KB

GIT.md

File metadata and controls

220 lines (199 loc) · 4.59 KB

BASICS, GITHUB

  • INIT, STATUS, ADD, COMMIT, LOG


Installation (linux)

sudo apt-get install git

Config name for the repository (onetime setting)

git config --global user.name "Rapid1898"

Config mail for the repository (onetime setting - use the mail using for github.com)

git config --global user.email "x@gmx.com"

Create repository in the actual directory

git init

Add file to the repository / staging area (prepared for later commit)

git add file.xyz

Add all html-files to the repo / staging area

git add *.html

Add everything to the repository / staging area from the directory

git add .

2nd way to add everything to the repository / staging area from the directory

git add *

Add readme-file

git add README.md

remove specific file from the repository / staging area (before commiting!)

git rm --cached index.html

Actual status in the git-directoy (eg. added files, changed files, not added,...)

git status

Commit files which are added / changed in the repo (with comment) - taking a "snapshot"

git commit -m "comment"

Show overview about the last activities

git log

Clone a repository in the actual path

git clone github-link

Link the acutal folder/repo to the github-repo

git remote add origin https://github.com/link/Test.git

Push with upstream definition (shorthand - to the master)

git push -u origin master

Push with upstream definition (longhand - to the branch "answer")

git push --set -upstream origin answer

undo add command before (all files get set back to the initial state)

git reset

undo the last commit

git reset HEAD~

ignore changes eg. for xlsx on the local machine

git stash


Pull (update) files from GitHub
(-u saves the paths - so at the next push - it must be only typed push)

git pull -u origin master


Enable pushing with ssh-key in Idea and VSCode

Enable open ssh agent: https://dev.to/aka_anoop/how-to-enable-openssh-agent-to-access-your-github-repositories-on-windows-powershell-1ab8
Run commands: https://stackoverflow.com/questions/56490194/vs-code-bitbucket-ssh-permission-denied-publickey

GITIGNORE

  • create a file ".gitignore" in the root-folder of the respository
  • this files / folders will be ignored when comitting (and so for pushing to the remote repository)
  • github has for eg. some problems with files > 100MB


all files in this folder will be ignored

add folder: /prg/dist/*

this specific file will be ignored

add file: /prg.xlsx

BRANCHES

  • BRANCH, CHECKOUT, DIFF, MERGE)


Create a new branch with the name "newFeature"

git branch newFeature

Change to branch "newFeature" (from the master-branch)

git checkout newFeature

Return to the master-branch

git checkout master

Delete branch

git branch -d newFeature

Change name of the branch - eg. for renaming branch "master" to "main"

git branch -m main

Create a new branch named "new"

git checkout -b new

Show the difference in the files

git diff head

Show only the differences for the files which are not commited yet

git diff --staged

Merge the branch with the master

git merge newFeature

WORKFLOW EXAMPLE


fork the initial repository on github (select personal account as target)

click fork-button in github

get the forked repository clone

click code-button to grab link

clone the repository to the local folder

git clone github-link

create branch "answer"

git branch answer

set current branch to "answer"

git checkout answer

see which branch is curently active (eg. main or answer)

git status

add all files to the stage (all in the current folder)

git add .

when something wrong were added (undo the whole add command)

(git reset)

shows the actual files on the stage

git status

commit files from stage ("take snapshot")

git commit -m "Completed"

push with upstream definition (to the branch "answer")

git push --set-upstream origin answer

change from main to the branch "answer"

select branch on git hub with button

make an pull request to the original repository

click pull request button