Git Contd..
- Lets create a new linux vm and try to configure git in this
- Creating an AWS EC2 Instance: Refer Here
- Creating an Azure VM: Refer Here
- Configure the username and email
- Git Configurations: Git has three config levels
--local
:- These configs are local to your repository and will be stored
.git/config
- These configs are local to your repository and will be stored
--global
:- This Configuration is user specific in an operating system
- On linux or mac systems
~/.gitconfig
- On Windows
~\.gitconfig
=>~ => C:\users\<username>
--system
:- This is configuration for the entire machine i.e. for all the users and all the repos
- Linux:
/etc/gitconfig
- Windows:
<git-install-root>\mingw64\etc\gitconfig
- When we have same configuration defined in different levels then the precedence
local > global > system
- Lets create a local config with username and email, Now create a new commit
- There are configurations which you can set Refer Here
- Exercise:
- Install Beyond compare or any other diff which you are comfortable with and configure it as local setting for your repository to use beyond compare as diff tool
- Change the editor for the local repository to notepad or notepad++ or sublime text or vscode on your windows
Aliases
- We can define aliases for the commands which we reuse often
- Lets try to create an alias for the following command
git log --graph --decorate --pretty=oneline --abbrev-commit
- Let create an alias called as history `git config –global alias.history ‘log –graph –decorate –pretty=oneline –abbrev-commit’
Git Protocols
-
Git can communicate with four protocols
- Local
- Http/Https:
- Authentication will be
- username/password:
- token based authentication: GitHub has moved to token based authentication
- Authentication will be
- Secure Shell (SSH):
- This is authenticate protocol which comes with advantage of being easy to setup
- Setup:
- Create a key-pair
ssh-keygen
- Now copy your public key contents to your server
- This for github
- Create a key-pair
- Git:
- This is one of the fastest protocols, however lacks robust authentication feature, generally suitable for read-only access to public projects.
-
Note: In GitHub to create PAT Refer Here
Git attributes
- Git attributes define the paths so that git treats the files as binary or text and what language to use for syntax highlighting.
- To create git attributes in the repo we will create
.gitattributes
- Refer Here for the collection of useful git attributes
Git Ignore
- This specifies intentionally untracked files to ignore
- To create a ignore specification create .gitignore file
- In the .gitignore file specify the files and folders which you want to ignores which you want to ignore
- We can generate .gitignore contents for all the popular language Refer Here
- Refer Here for the changeset to ignore the unnecessary files from your repo
Setting Upstream
- When you set up local repo first and then push the changes then we need to set the upstream
- To push a branch to remote repo
Adding multiple Remote Repositories
- Look at the below example
- Conceptual overview
Bare Repositories
- A bare repository will have only .git folder and it doesn’t have the working tree
- To create a bare repo
git init --bare
- This bare repository can be used by others to clone and submit commits to that
- Cloning from remote as bare repository