DevOPs Git Commands by Editorial Staff February 26, 2023 written by Editorial Staff February 26, 2023 Installing on macOS There are several ways to install Git on a Mac. The easiest is probably to install the Xcode Command Line Tools. On Mavericks (10.9) or above you can do this simply by trying to run git from the Terminal the very first time $ git --version If you don’t have it installed already, it will prompt you to install it. If you want a more up to date version, you can also install it via a binary installer. A macOS Git installer is maintained and available for download at the Git website, at https://git- scm.com/download/mac. Installing on Windows There are also a few ways to install Git on Windows. The most official build is available for download on the Git website. Just go to https://git-scm.com/download/win and the download will start automatically. To verify whether its installed or not Note:- that this is a project called Git for Windows, which is separate from Git itself; for more information on it, go to https://gitforwindows.org. To get an automated installation you can use the Git Chocolatey package. Note that the Chocolatey package is community maintained. You can view all of your settings and where they are coming from using: $ git config –list –show-origin root@vmlinux:/var/lib/git# pwd /var/lib/git root@vmlinux:/var/lib/git# git config --list --show-origin file:.git/config core.repositoryformatversion=0 file:.git/config core.filemode=true file:.git/config core.bare=false file:.git/config core.logallrefupdates=true root@vmlinux:/var/lib/git# Your Identity root@vmlinux:/var/lib/git# git config --global user.name "Venkat Chandra" root@vmlinux:/var/lib/git# git config --global user.email yvsc369@gmail.com $ git config –list –show-origin root@vmlinux:/var/lib/git# git config --list --show-origin file:/root/.gitconfig user.name=Venkat Chandra file:/root/.gitconfig user.email=yvsc369@gmail.com file:.git/config core.repositoryformatversion=0 file:.git/config core.filemode=true file:.git/config core.bare=false file:.git/config core.logallrefupdates=true How to check your Git configuration: The command below returns a list of information about your git configuration including user name and email git config -l root@vmlinux:/var/lib/git# git config -l user.name=Venkat Chandra user.email=yvsc369@gmail.com core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true How to cache your login credentials in Git: You can store login credentials in the cache so you don’t have to type them in each time. Just use this command git config –global credential.helper cache How to initialize a Git repo: Everything starts from here. The first step is to initialize a new Git repo locally in your project root. You can do so with the command below git init root@vmlinux:/var/lib/git# git init Reinitialized existing Git repository in /var/lib/git/.git/ Cloning a sample project root@vmlinux:/var/lib/git/.git# git clone https://github.com/yvsc369/devops1 Cloning into 'devops1'... remote: Enumerating objects: 32, done. remote: Counting objects: 100% (32/32), done. remote: Compressing objects: 100% (28/28), done. remote: Total 32 (delta 8), reused 21 (delta 3), pack-reused 0 Unpacking objects: 100% (32/32), done. root@vmlinux:/var/lib/git/.git# ls -l total 40 -rw-r--r-- 1 root root 23 Sep 30 06:42 HEAD drwxr-xr-x 2 root root 4096 Sep 30 06:42 branches -rw-r--r-- 1 root root 92 Sep 30 06:56 config -rw-r--r-- 1 root root 73 Sep 30 06:42 description drwxr-xr-x 4 root root 4096 Sep 30 07:11 devops1 drwxr-xr-x 2 root root 4096 Sep 30 06:42 hooks drwxr-xr-x 2 root root 4096 Sep 30 06:42 info drwxr-xr-x 3 root root 4096 Sep 30 07:08 jhc01 drwxr-xr-x 4 root root 4096 Sep 30 06:42 objects drwxr-xr-x 4 root root 4096 Sep 30 06:42 refs Create some files like text1, text2 and text3 root@vmlinux:/var/lib/git/.git/devops1# ls -lrh total 26M -rw-r--r-- 1 root root 5.0M Sep 30 07:33 text3.txt -rw-r--r-- 1 root root 5.0M Sep 30 07:33 text2.txt -rw-r--r-- 1 root root 5.0M Sep 30 07:33 text1.txt -rw-r--r-- 1 root root 55 Sep 30 07:11 info.txt -rw-r--r-- 1 root root 5.0M Sep 30 07:34 filename1.txt -rw-r--r-- 1 root root 56 Sep 30 07:11 demo.txt drwxr-xr-x 2 root root 4.0K Sep 30 07:11 Python_1 -rw-r--r-- 1 root root 5.0M Jun 2 2008 5MB.zip root@vmlinux:/var/lib/git/.git/devops1# git status On branch main Your branch is up to date with 'origin/main'. Untracked files: (use "git add <file>..." to include in what will be committed) 5MB.zip filename1.txt text1.txt text2.txt text3.txt nothing added to commit but untracked files present (use "git add" to track) root@vmlinux:/var/lib/git/.git/devops1# How to add a file to the staging area in Git: The command below will add a file to the staging area. Just replace filename1.txt with the name of the file you want to add to the staging area. git add filename1.txt root@vmlinux:/var/lib/git/.git/devops1# git add filename1.txt root@vmlinux:/var/lib/git/.git/devops1# git status On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: filename1.txt Untracked files: (use "git add <file>..." to include in what will be committed) 5MB.zip text1.txt text2.txt text3.txt How to add all files in the staging area in Git If you want to add all files in your project to the staging area, you can use a wildcard . and every file will be added for you. git add root@vmlinux:/var/lib/git/.git/devops1# git add . root@vmlinux:/var/lib/git/.git/devops1# git status On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: 5MB.zip new file: filename1.txt new file: text1.txt new file: text2.txt new file: text3.txt 0 comment 0 FacebookTwitterPinterestEmail Editorial Staff previous post Git Commands next post Git Commands You may also like Git Commands February 26, 2023 Git Commands February 26, 2023 Git Commands February 25, 2023 DevOps December 19, 2022 Leave a Comment Cancel Reply Save my name, email, and website in this browser for the next time I comment.