Git Workflow Overview
Files transition through three stages: working directory → staging area → local repository → remote repository.
Installation
$ sudo yum install -y git
$ git --version
git version 2.34.1
Repository Initialization
$ mkdir project
$ cd project
$ git init
Initialized empty Git repository in /home/user/project/.git/
$ ls -a
.git/
Staging Changes
$ touch README.md
$ git status
Untracked files:
README.md
$ git add README.md
$ git status
Changes to be committed:
new file: README.md
Commititng Changes
$ git commit -m "Initial commit"
[main (root-commit) 1a2b3c4] Initial commit
1 file changed, 0 insertions(+)
create mode 100644 README.md
Version Reversion
$ git log --oneline
1a2b3c4 (HEAD -> main) Update config
d4e5f6a Add feature
$ git reset --hard d4e5f6a
HEAD is now at d4e5f6a Add feature
Remote Repository Configuration
Adding Remote
$ git remote add origin git@github.com:user/repo.git
$ git remote -v
origin git@github.com:user/repo.git (fetch)
origin git@github.com:user/repo.git (push)
SSH Authentication
$ ssh-keygen -t ed25519
$ cat ~/.ssh/id_rsa.pub
Cloning Repositories
$ git clone git@github.com:user/repo.git
Cloning into 'repo'...
Pushing Changes
$ git push -u origin main
Pulling Updates
$ git pull origin main
Branch Management
Branch Opeartions
$ git branch
* main
$ git branch -a
* main
remotes/origin/main
$ git checkout -b feature
Switched to a new branch 'feature'
$ git checkout main
Switched to branch 'main'
$ git push -u origin feature
Tag Management
Tag Operations
$ git tag -a v1.0 -m "Initial release"
$ git tag
v1.0
$ git show v1.0
$ git tag -d v1.0
$ git push origin --tags
Tag-Based Cloning
$ git clone -b v1.0 git@github.com:user/repo.git