Kind of guide for Git Course by Codesai
Getting Started - Installing Git
mkdir my_project
cd my_project
git init
git status
echo "Hola Mundo" > hola.txt
git status
git add hola.txt
git status
# config your name and email
git config user.name "My Name"
git config user.email "myname@codesai.com"
git commit
# "Add my first file to project"
git status
git log
echo "Hola Europa" >> hola.txt
git status
git diff
git add . # Add all new and modified files and folders
git status
git commit -m "Add a very interesting line"
git status
git log
echo "A little mistake" >> hola.txt
git status
git diff
git restore .
git status
git branch feature1
git checkout feature1
# or
git checkout -b feature1
echo "A change in another branch" > another.txt
git add .
git commit -m 'Change in another branch'
git status
# now is the ugly one
git log
# nice log
git log --oneline --decorate --graph --all
git checkout main
echo "A change in main branch" >> hola.txt
git commit -am 'Change in main'
git log --oneline --decorate --graph --all
git checkout main
git merge
Option A: global
git config --global user.name "Your name"
git config --global user.email "email@dominio.com"
git config --global core.editor "loved_editor"
Option B: or local to this repo
git config user.name "Your name"
git config user.email "email@dominio.com"
git config core.editor "loved_editor"
Option C: or a fancy one-liner
git config user.name "User" && git config user.email "user@codesai.com"
alias | grep git
# Check where we are
pwd
git clone git@github.com:Codesai/git-course-practices.git
git log
echo 'hello' > new-file.txt
git add .
git commit -m 'New file'
git push
Option A -- using a remote server
# Create a remote repo (i.e. In github.com) with some file
# Clone repo for user1 and user2
git clone git@github.com:Codesai/git-course-practices.git user1
git clone git@github.com:Codesai/git-course-practices.git user2
Option B -- using a local server (trick)
# Create a local repo (i.e. In github.com) with some file
mkdir repo_server
cd repo_server
git init
git config user.name "Server" && git config user.email "server@codesai.com"
git config receive.denyCurrentBranch ignore
# Create some file and commit...
echo "Hola mundo!" >> hola.txt
git add .
git commit -m 'Create first file'
# Clone repo for user1 and user2
cd ..
git clone repo_server user1
git clone repo_server user2
? Question: Do we need to pull after clone?
# user1 -- do some changes
cd user1
echo "User 1 interesting thing" >> hola.txt
git commit -am 'User 1 Interesting thing'
# user2 -- pull
git pull
# or
git fetch
git merge
# or
git rebase
tip1: https://es.lipsum.com/
# user1 push new changes
cd user2
# add some changes & commit
git push
#rejected
git pull
# or
git fetch
git merge
# then
git push
# user1 push new changes
cd user2
# add some changes & commit
git push
#rejected
git fetch
git rebase
# then
git push
git tag
git tag v1.0
git tag -a v1.1 -m 'v1.1'
git show v1.0
git show v1.1
# push
git push --tags
#or
git push origin v1.0