Author - StudySection Post Views - 496 views
git

GIT Basic Commands

Introduction to GIT

Git is a content management and tracking system. It is a distributed revision control that is performed on stored data. It is a Source Code Management (SCM) system. It allows you to track the history of files. We can create different versions of this collection.
git remote repo

What we will cover in this post:

  • Basic commands of Git
  • How to make changes in the files
  • Sync my local repository with the remote repository
  • Add/commit them

Below is the list of some basic Git commands to get you going with Git:

  1. Git Config: It configures the author name and email address that will be used with your commits.
    git config –global user.name “Abc Xyz”
    git config –global user.email abc@example.com
  2. Git Init: It will create a new Local Repository.
    git init
  3. Git Clone: It will create a working copy of a local repository.
    git clone /path/to/repository
  4. Git Add: It adds one or more files to staging.
    git add <filename> //to add a particular file
    git add * //to add all the files
  5. Git Commit: It commits the changes to the head but not yet to the remote repository.
    git commit -m “Commit Comment”
  6. Git Push: It will send the changes to the master branch of your remote repository.
    git push origin master
  7. Git Status: It will list all the files you’ve changed & those you still need to add or commit.
    git status
  8. Git Checkout/Branch: To create branches and to switch between them.
    //Switch from one branch to another
    git checkout <branch>
    //Create a new branch and switch to it
    git checkout -b <branch>
    //List all the branches in your repository & tells you what branch you’re currently in
    git branch
    //Delete the feature branch
    git branch -d <branch>
    //Push the branch to your remote repository
    git push origin <branch>
  9. Git Pull: It will Fetch and merge changes from the remote server to your working directory.
    git pull
  10. Git Merge: It will merge a different branch into your current branch.
    git merge <branch>
  11. Git Add: After making changes to resolve conflicts manually, you mark the changed file.
    git add <filename>
  12. Git Diff: It will show you the merge changes.
    //View all the merge conflicts
    git diff
    //View the conflicts against the base file
    git diff –base <filename>
    //Preview changes, before merging
    git diff <source-branch> <target-branch>

The basic workflow of Git:

Step 1 − Modify Local files.
Step 2 − Add these files to the staging area.
Step 3 − Commit these files will move them from the staging area. After Push operation, it stores the changes permanently to the Git repository.

Step by Step commands to commit your code:

  1. Check status if you are in your branch or not.
    git status
  2. If you are not in your branch which you want to commit (If you are already in your branch you can skip this step). Go to your branch using-
    git checkout <your branch name>
  3. Add the files you want to commit. This will take files to the staging area, not on the repository.
    git add –all //to add all files
    git add . //to add all files
    git add <filename> //particular file
  4. Now use below command, to push code to the repository.
    git push origin <your-branch-name>

Step by Step commands to take a pull from the remote repository to your local:

  1. Check status whether your directory is clean or not. It means your directory should not contain any file that is not committed to your branch.
    git status
  2. If it is not, use the above steps (Step by Step commands to commit your code) to commit your changes.
  3. If directory is clean, pull the code from remote repo
    git pull origin master
  4. This will merge the master’s code to your local. You have to solve conflicts if occurred manually from local files. Then commit merged code to your branch-
    git push origin <your-branch-name>

Step by Step commands to create a new branch:

  1. Pull code from Remote repository using-
    git pull origin master
  2. Now, the common remote code will be on your local. Then create your new branch using-
    git checkout -b “new_branch”
  3. You will not see your branch on gitlab until you push your branch.
    git push origin new_branch

Get certification for your knowledge in the fundamentals of Computer functioning by clearing the Computer Certification exam conducted by StudySection. After going through this Computer Certification exam, you will be able to evaluate your basic knowledge of computers.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri