Git


 



The version control system is a management system that manages the changes we make in our projects. (Changes of the resource code or adding new files)

Git is a distributed version control tool.





Let's do a simple practical to get familiar with the git commands and to have a basic idea about Git.

  1. Log in to your GitHub account

  2. Create a repository in your GitHub account. That is your central repository.

  3. Let's create a local repository in the local machine

  4. Create a new folder in your machine. (In the location where you want to store the project)

  5. Go inside that newly created folder and right-click on the workspace. From the context menu, choose "Git Bash Here".

  6. It will open the git bash

  7. Initialize the empty folder to make it a git repository. Give the below command in the git bash 

    git init

  8. Add the remote repository as my origin. 

    git remote add origin <<git-repo-url>>

  9. Fetch all the files from the central repository to the local repository.

    git pull origin master

  10. Go to the folder location in your machine, create a new text file & type some content in it and save.

  11. Go to the git bash terminal. Let's see what files that were added to the local repository. For that give the below command.

    git status

    The newly created file will be appeared saying that it is an untracked file. Because we did not commit the file.

  12. Let's add that file to the index/make it a tracked file ( git add edu.txt )

    git add <<file-name>>

  13. Now when the command " git status " is given, the newly created file will be displayed as a new file.

  14. Let's commit to the changes. ( git commit -m "First Commit" )

    git commit -m "commit-message"

  15. Let's create multiple new files and type some content in each file

  16. Check the current status using " git status "

  17. Modify the file which was created first and check the status using " git status "

  18. Let's add all the new files and the changes to the existing files to the index

    git add -A

    After that, if you check the status, all the files will be displayed as tracked files.

  19. Let's commit all the changes. ( git commit -a -m "Commit all changes"

    git commit -a -m "Commit message"

  20. Let's see how git stores all those commits

    git log

  21. Create a local branch.

    git branch <<branch-name>>

  22. Let's checkout/change the branch which you are currently working on, to the newly created branch.

    git checkout <<branch-name>>

  23. You can list down the files of the particular location/branch using the command " ls "

  24. Let's create a new file in the new branch and will merge the new branch into the main

    Create the file 
    Commit the changes ->          git commit -a -m "Commit message"
    Merge the new branch into main ->     git merge <<new-branch-name>>

  25.  If you want to observe the changes of a single file, use the command
    " cat file-name " ->  cat edu.txt   

  26. "git pull" can be achieved with the combination of two commands as follows

    git pull = git fetch + git merge

    Let's practice the " rebase " feature in Git


  27. Create a new branch
             git branch test-rebase

    Checkout to the new branch
             git checkout test-rebase 

    Create several new files in the project location. 
    Add them to the index
            git add -A

    Commit them
            git commit -a -m "Adding for rebasing"

    Before using the rebase feature, go to the master and the test-rebsae branches and go through the 2 lists with the command of " ls ". Then after the rebase, you can easily find what has happened after using the rebase command

    You should be in the " test-rebase " branch. Then let's use the rebase command
           git rebase master

    Go back to the master branch
           git checkout master

    Do rebasing
           git rebase test-rebase

  28. Checkout to the master branch

    git checkout master

  29. Create a new branch from master branch

    git branch final-test-branch

  30. Add some files and modify the existing content as you wish

  31. Commit all those changes

    git commit -a -m "Final Commit"

  32. Next we have to push them to the github. But the branch called " final-test-branch " is not there in the remote repository. Because we created it locally. Lets publish that branch. 
    git push --set-upstream origin final-test-branch )

    git push --set-upstream origin <<branch-name>>

  33. Push all the changes into the remote repository
    git push origin final-test-branch )

    git push origin <<branch-name>>

Comments