Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Setting git settings:

git config –global user.name ” ”


git config –global user.email <>
git config –global core.editor ”code -wait”  console waits for you to stop using VS code
git config –global core.autocrlf true  solving the problem with different end lines on
different operating systems
git config –global -e  shows all the settings in VS code file
code  opens VS code

Basics of working in git


git init  creating an empty repository in current location

git add file1_name file2_name, …, filen_name  adding files to the staging area

git commit -m ”message to the commit”  commiting staged changes to the repository

git status  prints the status of staged area and repository

git status -s  prints the short version of git status

git commit -am ”message to the commit”  skipping staging area

git ls-files  prints files in staging area

Removing and renaming files


git rm <files_name>  removes files both from the working directory and staging area
git rm –cache <files_name>  removes files just from the staging area
git mv <old_name> <new_name>  renames the file both in working directory and staging
area

Files ignored by git


To make git ignore some of the files (f.ex. log files) we create a .gitignore file, in wich they are
stored

Viewing made changes


git diff –staged  shows the difference between staged area and last commit
git diff  shows the difference between staged area and working directory
git config –global diff.tool vscode
git config –global difftool.vscode.cmd ”code –wait –diff $LOCAL $REMOTE”
^- sets vscode as a default tool to look for made changes
Git difftool (--staged for staged area to last commit)  shows the difference between staged
area and working directory in difftool app
git show <identifier of the commit/HEAD~<how many commits down>  shows changes
made in a commit
git ls-tree <identifier of the commit/HEAD~<how many commits down>  shows files
modified in commit
git show <identifier of the file in the commit>  shows content of this file on this commit
Git log  history of all commits (latest on top)
Git log –oneline  short version of git log

Unstaging files
git restore –staged <file name>  delete staged changes of given file (all the changes are
just in working directory), it goes back to last commit version

Discarding local changes


Git restore <file_name>  changes working directory version to staged changes version
Git clear -f  removes untracted files (not yet added to the repository)

Restoring File to the previous verion


a) From working directory to gitLab:
git restore –source=HEAD~1 <file_path>  restores last version of the file

Connecting with remote repository


git add Lab2/Laby2_zadania_na.py
git commit -m "test commit"
git remote add origin https://gitlab-stud.elka.pw.edu.pl/mgrzanka/pipr-lab.git
git push -u origin main
b) From gitLab to working directory:
git clone https://gitlab.com/your-username/your-repo.git  creates a copy of the repository
in your working directory
git pull origin main  just udates current, local repository on your computer

You might also like