GIT
- Distributed Version Control System
- Collaboration
- Source Code Management
- Open Source Projects
- Version History
- Ability to rollback
Developed in 2005 by Linus Torvalds for managing Linux Kernel Development.
Key Concepts:
- working directory
- staging area / index
- version database / repository
Basic Git commands
Check existing configuration
git config -l
Git configuration
git config --global user.name "apurwa"
git config --global user.email "apurwa@gmail.com"
Check existing configuration
git config -l
Check git status
git status
Initialize current directory in GIT
git init
Note: .git folder is created
Start tracking files by adding files to staging area
git add .
Note: . refers to current directoryCommit to version database
git commit -m "first one"
Check git logs
git log
Add remote repo
git remote add devops git@github.com:apurwa-np/devops.git
Push to remote repo
git push devops main
Pull from remote repo
git pull devops main
Clone remote repo
git clone git@github.com:apurwa-np/devops.git
Note: A public repo can be viewed and cloned by anyone. But only users with SSH keys can push to the repo.
Undoing in GIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GIT branching
- Independent feature development
- Parallel collaboration
- Conflict avoidance
- Modular development
- Easier Rollback
Create new branch
git branch greet
Switch to new branch
git checkout greet
Make changes for new feature
app.py
from flask import Flask
app=Flask(__name__)
@app.route('/')
def webout():
return '<h1>DevOps is fun.</h1>'
@app.route('/greet')
def greet():
return '<h1>Welcome to the new feature</h1>'
app.run(host='0.0.0.0',port=7000)
Note: Added a new route /greet in python flask app
Add a new commit
git commit -a -m “new route /greet added in new branch”
Push the new branch to remote repo
git push devops greet
Merge the new branch into main branch
git merge greet