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:
name:editor: vim
creating ssh key:
github->settings-> new key->
cdcd
ssh keygen -t RSA
cat ~/.ssh/id_rsa.pub
Clone
git clone xxx.git basicgit1
or
cd
mkdir basic-git-2
cd basic-git-2
git init (it will create .git folder)
git remote add origin git@xxx.git
git remote -v
Add and update Files
touch index.html
git status
show unbranched status
git add index.html -> staging area
git commit -m "message"
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
create a file and add txt
stage the changes with git add command (file name or use "." to add all changes)
check status with "git status"
commit wit a commit message
push upstream (git push origin master)
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...
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
Last updated
Was this helpful?