Giter Club home page Giter Club logo

git-session's Introduction


Logo

Git Session

In this session, I will give you a tour of the important features of Git. This tool allows you to do versioning and to keep track of the project modifications

Table of Contents

Git Definition

Git is an open-source Distributed version control systems used for tracking project changes and revisions across different teams.


drawing

Git saves different versions of projects in a folder known as a Git repository.

what is git repository

A Git repository is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed. drawing

Git architecture

drawing *

Getting Started

Init

The git init command allows to initialize a new empty git repository. This will create a .git folder which will contain the information about our versioning.

cd my-project
git init

Config

Before starting to do anything it is important to configure git. So we will have to configure user information. This information will be visible in the history and will allow to know later who did what.

git config --global user.name "My_Name"
git config --global user.email "[email protected]"

Status

git status

This command allows to get the state of the history,

Versioning

Add

git add <file-name>       //add file name to the staging area
git add  --all            //add all the files to the staging area

A particularity of git is its staging system which allows you to select the files to follow during the next commit. You can think of it as a "waiting area" where you list the files you want to be saved.

Commit

 git commit -m "message to describe your commit"

Make a commit A commit is a step in the history of your project, a step that we can identify with a particular message.

Log

git log

The log command allows us to obtain information on the different commits of our project.

git log --oneline

Allows to display the history with one line per commit example:

git log --oneline

42f8151 fix bugs fa1c031 redesign b93b035 add a style file fb7597a first commit

Checkout

 git checkout <commit-id>

In short you have gone back in time as a viewer. You can see the project as it was at the time of the commit while having the ability to return to the "present". We use this command to watch old commits,

Exemple

git checkout fa1c031

return:

Note: switching to 'fa1c031'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.

enter image description here

 git checkout master   //if you want to go back to the actual state

Revert

git revert <commit-id>

This command will undo what was done at the time of the commit by creating a new commit. This does not alter the history but will add a new reversal commit

Example

git revert fa1c031

result:

Removing filee.txt [master acbb7e8] Revert "redesign" 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 filee.txt

the file that i was added in the "redesign commmit" will be removed and a new commit will be created

enter image description here

Reset

git reset 

Deletes all files from the staging area, without deleting the changes.

git reset <commit-id>
  • Allows you to go back to the commit,
  • Resets the staging area while leaving your working folder as is. The history will be lost (subsequent commits will be lost, but not your changes).

This command mostly allows you to clean up the history by resubmitting a single commit instead of too many scattered commits.

Example :

git reset fa1c031

enter image description here

git reset <commit-id> --hard
  • Returns to the <commit-id>
  • Reset the staging area and working folder to match. All changes, as well as any commits made after the <commit-id> will be deleted. Use with extreme caution

Branches

A branch in Git is a way to keep developing and coding a new feature or modification to the software and still not affecting the main part of the project. We can also say that branches create another line of development in the project. The primary or default branch in Git is the master branch

Branch

git branch                     # Allows you to list the branches
git branch branch_name         # Allows you to create a new branche  branch_name 
git branch -m branch_name      # rename the current branch to  branch_name
git branch -d branch_name      # delete a branch

The branch command allows you to manage everything related to branches (adding, listing, removing, renaming)

Checkout

git checkout branch_name                   

Allows you to go to an existing branch.

Example:

 git branch my_first_branch           #create my new branch
 git  checkout my_first_branch        #switch to my new branch
 
 git add .
 git commit -m "my first commit in my new branch" #add a commit in this branch

Result:

Switched to branch 'my-first-branch'

enter image description here

Merge

git merge branch_name                   

Merge allows you to connect two branches together and fuse them. The fusion of two branches is always done from the main branch.

Example:

git chekout master    # we must switch to the main brach
git merge my-new-branch 
                  

enter image description here

Remote

Remote

git remote add <alias> <chemin/url>  # Add a new remote repository

The remote command allows you to create, display and delete connections. These connections should be considered as simple aliases of the real repository path.

drawing

Exemple:

git remote add origin https://github.com/khaliljedda/git-session.git  

Push

git push <remote> <branche>  

The push command is used to transfer local commits to the remote repository.

drawing

example:

git push origin master  

Fetch

The fetch command allows to import the information from the remote repository. The import is done through special branches to give us the possibility to compare it and if necessary merge manually.

git fetch <remote> # Retrieves all branches and commits 
git fetch <remote> <branche>

drawing

Pull

The pull command allows you to do a git fetch followed by a git merge in a single command.

git pull <remote> 
git pull <remote> <branche> # pull from a specefic branch

drawing

git-session's People

Contributors

khaliljedda avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.