Git

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

$ git --version <- This is to check if git is install on your PC

git version 2.30.2.windows.1

$ git config --global color.ui auto


$ git config --global user.name "yourusername"
$ git config --global user.email "[email protected]"

Note: Use global to set the username and e-mail for


every repository on your computer.
If you want to set the username/e-mail for just the
current repo, you can remove global

$ mkdir example <- this creates a directory named example on your PC


$ cd example <- This changes the directory you are currently in to example

$ git init <- This is to initialize git into the example folder and creates a new
repository in your PC
Initialized empty Git repository in /Users/user/myproject/.git/

$ rm -rf .git <- To delete/uninitialize a git repository

$ touch index.html
$ touch script.js
$ touch style.css
This is to create a files named index.html, script.js, style.css
in the example folder

$ ls <- This is to list the files in the example folder


index.html script.js style.css

$ git add index.html <- add/stage index.html to the repo

$ git rm --cached index.html <- this is to unstage index.html from the repo
rm 'index.html'

$ git add . --> add/stage all in the directory


$ git add -A ----> same as above
$ git add --all ----> same as above

$ git status
On branch master

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html
new file: script.js
new file: style.css

Untracked files:
(use "git add <file>..." to include in what will be committed)

$ git rm -r --cached . --> to unstage/remove all in the directory

$ git commit -m "My commit Message"


[master (root-commit) 221ec6e] First release of Hello World!
3 files changed, 26 insertions(+)
create mode 100644 script.js
create mode 100644 style.css
create mode 100644 index.html

$ git log <- To view the history of commits for a repository


commit 09f4acd3f8836b7f6fc44ad9e012f82faf861803 (HEAD -> master)
Author: yourusername <[email protected]>
Date: Sun Apr 26 14:35:54 2023 +0100

Updated index.html with a new line

commit 221ec6e10aeedbfd02b85264087cd9adc18e4b26
Author: yourusername <[email protected]>
Date: Sun Apr 26 14:33:07 2023 +0100

My commit Message

$ git branch -M branch_name <- This is to create a branch


$ git branch -d branch_name <- This is to delete a branch
$ git branch <- This is to check all the branches in that repository
* master <- '*' Shows that you are currently on this branch
main

$ git checkout branch_name <- This is to switch from one branch to another
git checkout branch_name
Switched to branch 'branch_name'

$ git remote add origin https://github.com/yourusername/example.git

$ git push -u origin main


info: please complete authentication in your browser...
Enumerating objects: 405, done.
Counting objects: 100% (405/405), done.
Delta compression using up to 4 threads
Compressing objects: 100% (391/391), done.
Writing objects: 100% (405/405), 14.15 MiB | 603.00 KiB/s, done.
Total 405 (delta 47), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (47/47), done.
To https://github.com/yourusername/example.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.

Commands
git --help
ctrl + l
git show
cd .. --> to go back
dir
git config
git config -l
ls -a
git merge main

You might also like