Skip to content

Instantly share code, notes, and snippets.

@VikashSaharan1
Last active March 26, 2023 03:43
Show Gist options
  • Save VikashSaharan1/ddab997c3dc076552a7ddc254bddf59e to your computer and use it in GitHub Desktop.
Save VikashSaharan1/ddab997c3dc076552a7ddc254bddf59e to your computer and use it in GitHub Desktop.
git commands list

What is a Git?

Git is a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows. 

Git is a DevOps tool used for source code management. It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to tracking changes in the source code, enabling multiple developers to work together on non-linear development.

What is a Git protocol?

      This is a special daemon that comes packaged with Git; it listens on a dedicated port (9418) that provides a service similar to the SSH protocol, but with absolutely no authentication.
      The default SSH port (22) is dedicated to Git and SSH application network traffic.

How to Setup git in your machine

For Windows

1. Download git for this link https://git-scm.com/download/win
2. Install git with Git Bash
3. Setup your identity via git config
          $ git config --global user.email "email"
          $ git config --global user.name "username"

For Ubuntu Linux

For Mac

Git Terminologies:-

clone: it is means create a local copy of Repository push: using for pushinf yt=he code on remote repository pull: pulling the code from remote repository commit" commit the code from local to staging area logs: logs means you can see details of previous commit
config: you can see or modify configuration of git users in your local system. diff: see the difference between previous and new changes staging area: When you create a git commit, Git takes changes that are in the staging area and make them as a new commit. You are allowed to add and remove changes from the staging area. The staging area can be considered as a real area where git stores the changes.

syntax: $ git clone <repository_url>

How to change origin url in git

$ git remote add origin remote

How to merge two repository and make one

  1. open your terminal and go to source repository where you want merge target repository. Exp: cd demo1
  2. git remote add -f <new_branch_name> <target_repo_url> Exp: git remote add -f old_demo2 https://github.com/VikashSaharan1/Helloworlld
  3. git merge <new_branch_name>/<repo_branch_name> --allow-unrelated-histories Example: git merge old_demo2/master --allow-unrelated-histories
  4. Resolve conflict files Like README.md
  5. git status
  6. git add .
  7. git commit -m "merge demo2 in demo1"
  8. git push -f origin master

How to merge two repository and make one from commit id

  1. open your terminal and go to source repository where you want merge target repository. Exp: cd demo1
  2. git remote add -f <new_branch_name> <target_repo_url> Exp: git remote add -f old_demo2 https://github.com/VikashSaharan1/Helloworlld
  3. git cherry-pick <commit_id> Example: git cherry-pick d7dda7733ea7a7e5b56095196834f7ae0e48fb45
  4. git add .
  5. git commit -m "merge demo2 in demo1"
  6. git push -f origin master

Get All Remote Branch and Print Via CMD

for /F %r in ('git branch -r') do echo %r

Git Sync All Branches Via CMD into Current branch

for /F %r in ('git branch -r') do ( git branch --track %r) && git fetch --all && git pull --all

Git Sync All local branches from Remote

for /F %r in ('git branch') do git switch %r && git pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment