Introduction
Git is a free, open source version control system that developers and analyst use for tracking changes,collaborating and managing project history efficiently, allowing them to work offline and merge their work seamlessly.
Getting started
Before getting started with Git you’ll need to configure by setting your email and user name.
This is important for version control system as each Git commit uses this information
An example
git config --global user name "nashipae"
git config --global user. email "nashipaentungani@gmail.com
The Git work plan
The life cycle of file has 3 stages. They include:
Your working directory - This is where you are actively working on the file or editing
Staging area-This is a loading dock for changes you want to save (almost final)
The repository-This is a permanent storage area for your project
An example, GitHub, GitLab
Essential commands
Starting a project
There are 2 ways to configure this
- Initialize a new project
git init
- Clone an existing project
git clone (github project)
Checking status and tracking changes
Git allows you to check the status of a file
git status-see what has been changed in a file
An example
git status
on branch master
no commits yet`
changes to be committed:`
use `git restore --staged ..."to unstage
`
new file: index.html
git diff- see detailed changes made to a file
git add (file name)-adding specific file to the staging area
git add.- adding all changes to your staging area
Saving your work
To save changes on Git we use the command
git commit -m "commit message"
To view history on commits for repository you can use the git log command
Pushing your code
To create a remote connection to github we use the command
git remote add origin "Github project"
To push to a main branch, we use the command
git push origin main
To push for the first time
git push -u origin main
Pulling code
git pull origin main
See what has changed
Version control deals with understanding what changes have been made to a file
For this you have to check the history of your commit
git log- see commit history
git log --oneline see compacted history
git blame(file name)find out who made changes
git diff (commit 1) (commit 2)- compare between commit
If you made a mistake during staging you need to go back to your previous changes, we use the command
git rese HEAD*
We have 3 examples of this
git reset --soft (HEAD ~1)
git reset --hard (HEAD ~1)
git reset --mixed(HEAD ~1)
Top comments (0)