This document discusses various Git commands and concepts:
- It explains how to install Git on Linux and Windows, generate SSH keys, clone repositories, customize Git settings, work with branches and tags, and more. Commands covered include git clone, config, init, add, commit, push, pull, branch, tag and log.
- Setting up SSH keys allows pushing code without authentication. Aliases create shorthand commands for common Git operations like status and commit. Tags mark specific points in a repository's history. Branches enable parallel development.
Scanning the Internet for External Cloud Exposures via SSL Certs
Getting started with git
1. GETTING STARTED WITH GIT
• git is a vcs version control system for managing code.
• git is a centralized distributed vcs
• github requires subscription for private repos, on bitbucket we can have a free private repo.
pawaan.v[at]gmail.com
2. HANDS ON USING LINUX DISTRO OR WSL ON WINDOWS
• If you are windows 10 wsl (windows subsystem for linux) a full blown Ubuntu distoro can be installed
ref : https://docs.microsoft.com/en-us/windows/wsl/install-win10
• On linux install git from apt for deb based distros and yum/dnf for rpm based distros
#apt-get install git -y
#yum install git -y
#git --version
• Check wsl home directory from command
#echo $HOME
#echo $USER
• Navigate to windows user directory using the command
#cd /mnt/c/Users/username
#ls
•
pawaan.v[at]gmail.c
3. GENERATING AND ADDING SSH KEYS TO GITHUB OR BITBUCKET
• ssh-keygen –t rsa -b 4096 -C email@example.com
• eval $(ssh-agent -s)
• ssh-add ~/.ssh/id_rsa
• Verify the permissions of id_rsa to be 600
• Once the key is generated add it to
git at: https://github.com/settings/keys
bitbucket at: https://bitbucket.org/account/user/<user>/ssh-keys
• Testing ssh authentication to git and bitbucket
ssh -T git@github.com
ssh -T git@bitbucket.org
• Configuring global options
#git config --global --edit
4. CLONING INTO AN EXISTING GIT PROJECT
• Git clone is used to clone an existing project from git, pull can be http based and ssh based.
-If a pull is done from http method , when the user wants to push the code every time the
authentication needs to be entered.
-If code is pulled using ssh , user need not provide credentials every time while pushing the code
taking into account that ssh keys are already added to the account
• #git clone https://github.com/pawaanv/cipher-setup
#cd cipher-setup
#echo “adding Version file”
#echo “version 1.0 > version”
#git commit -m “added version name”
#git push
• Create a empty git project
#mkdir njord
#cd njord
#git init
#ls
5. ALIASES
• Shorthand commands for git instead of typing long commands
#git config --global alias.co checkout
#git config --global alias.br branch
#git config --global alias.ci commit
#git config --global alias.st status
#git config --global alias.cl clone
#git conifg --global alias.ph push
#git config --global alias.pl pull
#git pl --help
• While storing files on git we don’t want to put password files and confidential info in public repos,
avoiding larger files
#echo “passwords” > .gitignore
• Checking the difference between the commits
#git diff commit1 commit2
6. GIT CUSTOMIZATION
• #git status
#git config -l
#git config -e
#git config --global user.name “Pawan kumar”
#git config --global user.email pawaan.v@gmail.com
#git conig --global color.ui auto
#git status
refer : https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
• Adding files to the empty git repo
#touch httpd.sh
#git add httpd.sh
#git add -A
#echo > “#!/bin/bash”
#git commit –m “apache”
#git push -v
#git status
if you are single user working on the git with multiple devices and want to get the latest changes to be
pulled then add below code to .bashrc
#echo >> “git -C ~$USER/cipher-setup/ pull” >> $HOME/.bashrc
7. REMOTE GIT REPOS, TAGS
• Check the remote git repo status from command
#git remote –v
#git remote add pb https://bitbucket.org/cipheronic/cipher-setup
#git fetch pb
#git remote show origin
#git remote rename pb cipher
#git remote
#git remote remove cipher
#git remote
• Git repos can be tagged in history
there are two types of tags “Annotated tags & lightweight” tags
Annotated tags store full git objects and databases
Lightweight tags are like branches they just pointers to the git branch location
#git tag -a v.1 -m “my version v.1”
#git show v.1
git push does not push the tags it has to be done explicitly
#git push origin v.1
To push all the tags
#git push origin --tags
8. GIT BRANCHING
• By default user will be working in master branch ( default which is created when git init is run)
user check check the current branch they are working under using the command
#git branch
• New branch can be added with the command
#git branch test
#git branch -v
• User can switch to the new branch with the command
#git brahch test
#git checkout test
or
#git checkout -b test
#git branch –d test
#git branch --merged
#git branch --no-merged
• Logs
#git log
#git log --oneline –decorate
#git log --pretty=oneline
#git
pawaan.v[at]gmail.c