> For the complete documentation index, see [llms.txt](https://shahidmobin.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shahidmobin.gitbook.io/linux/learn-cybersecurity-with-shahid-mobin/git.md).

# Git

Why Git?

Distributed, Multi-Branch source code management

## Install Git

MAC: brew install git

Linux: sudo apt-get install git

### Configuration

#### Windows

git config --global core.autocrlf true

git config --global core.safecrlf true

#### Mac/Linux

git config --global core.autocrlf input

git config --global core.safecrlf true

config file: cat \~/.gitconfig

email:&#x20;

name:editor: vim

{% file src="/files/Mj200513tv1dcDiMZ1KX" %}

creating ssh key:

github->settings-> new key->&#x20;

cdcd<br>

ssh keygen -t RSA

cat \~/.ssh/id\_rsa.pub

## Clone

git clone xxx.git basic*git*1

or

cd

mkdir basic-git-2

cd basic-git-2

git init (it will create .git folder)

git remote add *origin* <git@xxx.git> &#x20;

git remote -v

### Add and update Files

touch index.html

git status&#x20;

show unbranched status&#x20;

git add index.html -> staging area

git commit -m "message"&#x20;

git push origin master -> to push into remote repository

Pulling from upstream so the upstream is the remote repository and the downstream is the local repository. (to update local file we pull from remote repo)

git pull origin master

### Procedure

1. create a file and add txt
2. stage the changes with git add command (file name or use "." to add all changes)
3. check status with "git status"
4. commit wit a commit message
5. push upstream (git push origin master)
6. always start with pull (git pull origin master)

## Workflow

to tag for first production release

git tag -a v1.0 -m "Add first tag "  -> it will tag the most recent commit

git show v1.0

git push --tags origin master

### Branch

developer branch

git branch developer

git log

git log --oneline --decorate --graph --all

glog

git branch -> to list branches

git  checkout develop

git add file or .

git commit -m "mesage"

git push origin developer

### Feature branch

git branch feature1

git checkout feature1

git add .

git commit oringin -m "messgae"

git push origin feature1

#### Add gitignore

git checkout developer

touch .gitignore

echo "todolist.txt" > .gitignore

git add .

git commit -m "message"

git push origin develop

git checkout developer

git merge feature1

delete feature1 branch

git branch -d feature1

Version 2 release

git checkout master

git merge developer

git tag -a v1.1 -m "added some features"

## Common Problems

for advanced revert...

{% embed url="<https://www.youtube.com/watch?v=NXaEImbo-n8>" %}

Merger Conflicts

Local and remote repo conflicts

upstream->downstream

downstream-> upstream

Local only conflicts

Fixing merge conflicts with VSCode

The "3 Tree concept"

"git checkout"

git revert

git reset
