GIT Command Lines

These are the Git command lines that I have used frequently in the project.
  • Switch to the existing branch:

    git checkout <branch_name>
    
  • Switch to a new branch:

    git checkout -b <origin_brnach> <new_branch_name>
    
  • Add all local changes to the local repository:

    git add .
    
  • Commit all local changes:

    git commit -m"commit message"
    

    The standard commit if GitLab is connected with Jira Software:

    git commit -m"CHD-86: Update code for contract API"
    

    CHD-86 is your task on Jira Software

  • Push commits to the remote repository:

    git push
    
  • Pull code from the remote repository:

    git pull
    
  • Merge your branch codes with the other branch (ex, develop):

    git checkout <your_branch>
    git merge develop
    

    If it shows many conflicts, you should fix it!

  • Roll back to the specific commit code

    Firstly, you should determine the commit that you want to roll back:

    git log --oneline
    

    The result will show:


        The next step is to roll back to the commit:
     git reset --hard <commit_hash>

        For example, commit_hash is 256cd72, which you want to go back to.

        (Optional) If you want to push your code to the remote repository:

     git push origin --force
  • Cherry pick
  • Create a new MR to revert a specific commit

    Step 1: Switch to main branch (ex, develop)

    git checkout develop
    

    Step 2: Check out the new branch from develop

    git checkout -b revert-ckt-413
    

    Step 3: Go to the GitLab or GitHub repository, view the commit you want to revert

    For example, I had requested to create a new MR to revert CKT-413, which had been merged into develop. I will choose to commit that my leader had merged. (now at 14/08/2025)


       git revert -m 1 351a6bc6

            Hint: Choose to commit that the leader had merged into the main branch

            Step 4: Push the revert branch to the repository and fix the conflict if it exists

       git push origin revert-ckt-413

Nhận xét

Bài đăng phổ biến từ blog này

How to check if your IP can connect to another address

Cassandra Query Language (CQL) - CREATE TABLE