dddddddssssOpen gitbash
Create a new repository using mkdir command for github, gitrepos, and titan
Git Init
The git init command is the first command that you will run on Git. The git
init command is used to create a new blank repository. It is used to make
an existing project as a Git project. Several Git commands run inside the
repository, but init command can be run outside of the repository.
The git init command creates a .git subdirectory in the current working
directory. This newly created subdirectory contains all of the necessary
metadata. These metadata can be categorized into objects, refs, and
temp files. It also initializes a HEAD pointer for the master branch of the
repository.
Purpose of git init
The git init command creates a new Git repository. It can be used to convert an existing,
unversioned project to a Git repository or initialize a new, empty repository. Most other Git
commands are not available outside of an initialized repository, so this is usually the first
command you'll run in a new project.
Whenever creating a new repository use git init command
After running git init command we can see that “.git” repository is created
After doing git init command for the directory that will be master branch
The above command will create a new subdirectory named .git that holds all
necessary repository files. The .git subdirectory can be understood as a Git
repository skeleton. Consider the below image:
An empty repository .git is added to my existing project. If we want to
start version-controlling for existing files, we have to track these files with
git add command, followed by a commit.
We can list all the untracked files by git status command.
1. $ git status
Consider the below output:
In the above output, the list of all untracked files is displayed by the git
status command. To learn more about status command, visit Git Status.
We can track all the untracked files by Git Add command.
Type ls -a it will show ./ ../ .git/ this .git/ will maintain all versions, all history and all the
configurations of a git repository.
So titan is our git repository it will maintain all versions, history and configurations with the
help of .git/
Real time using git status
Create some directory and files
Run git status command
It will list out all untracked files
Those untracked files are not consider for commit
If you want to track all unwanted track files use the below command
Git add . (. is the current directory)
First time using git commit without login
Add mail and username
Git config –global user.email “mano92.brock@gmail.com”
Git config –global user.name “manobrock”
Again run git commit with login it will not show any error
Now its all files added to commit and now it’s a tracked files.
We doesn’t insert any files
Steps:-
1. Set the name and email for git to use when you commit:-
Git config –global user.email mano92.brock@gmail.com
Git config –global user.name “manobrock”
2. Create a directory
3. Initialize dir with
Git init
4. Create Readme.md file
Git add (Staging)
Git commit (Local Commit)
5. Create Remote repository on
Github, bitbucket, codecommit etc
6. Clone repo to local
Git clone url
7. Local to Remote integration
Cd to local repo
Git remote add origin
Ssh://git@github.com/[username]/[repository-name].git
Git push
Git pull (to fetch latest changes)
Github introduction
I am already having an account
Login done successfully
Create a new repository
Just select private repository and click on create repository
Repository created now
Here we have a two url one is https and ssh
We can create a repository using command line with the below steps
If we having existing repository follow the below steps with the help of command line
Or import the code form another repositor using command line
Copy this from the github
And paste in the github and run the command cat .git/config
git branch -M main
we are changing the master branch to main branch
git push -u origin main
when you run this command git push this will change will happen on
github from the local repository its synching local repository to
remote repository for that we need authentication
After login with sign in your browser
Authenticated successful
Our changes pushed from local to remote we can see that after refresh
Here we can see the commit id tis used for versioning
Make some changes in vim file and comeout through :wq
Now check with git status it will show modified file with time
Now iam going to add the file using “git add Neptune1.py”
Post that use git commit command
Now its committed successfully but its done in locally not remotely
Post push this changes to our local
Usisng the below command “git push origin main ”
Changed things showing here in git
Git log also show history in our command line
Using this commit id we can expand our changes
Using the command git show commit_id
If you are feeling commit id is very long then use this “git log --oneline” command, so that commit id
will be short instead of long.
Whenever we make the changes Eg: some line is removed some line is added that will show in both
command line as well as git hub site. If removed it will show in red color and if we add it will show in
green color.
Follow the below steps
1. Git add .
2. Git commit “commit message”
3. Git push origin main
4. Git log –oneline
5. Git show commit_id
We can made the changes in the site itself
Changed were made just now for neptune10.py
If you want to pull the latest changed using the “git pull” command
Our latest change is neptune10.py
Git show it will show the latest commit id in the first
Main or master branch will keep all files stable copy over here
Now I am in main branch
Now I am creating a new branch thru local repository using the below command
Git branch -c sprint1
Git branch -a will list all branches under titan repository
As of now we have only two branches (main and sprint1)
Switch to sprint1 using below command
Git checkout sprint1
Existing branch we need to switch use the below command
Git switch main
I can see the same set of data in temp branch
For remove use git rm it will remove the file and also from the index and staging area
Observed that it’s removed from staging also
Currently what Branch we are working that branch should be used for git push
Eg: working in temp branch name as sprint1
Git push origin sprint1
So, we did some changes in sprint1 temp branches.
I want to merge with main from sprint1 temp branches use the below command
Git merge sprint1 (sprint 1 changes will merge with main branch)
If you going to merge with master branch or any other branch you should be in that branch
Eg I am going to merge with main branch. So I am in main branch.
See that we are merged sprint 1 with main branch
Both branches are looking same
If you want to push all files from temp branches sprint1
Git push -all origin (Already we pushed all the files to remote repository so that its showing
message as everything up to date)
I will delete my repository from local
Rm -rf titan
Deleted now don’t worry I am having backup in remote repository
Again, we want same repository in local use git clone
See now its copied into local
I made some changes in the file
Run git diff command see the difference what lines added or removed
Again, making some changes in the same file
It will show the difference.
post git add . command Git diff will not work should use git diff –cached
I am going to commit some changes. Suddenly observed that I don’t want that changes we use git
restore –staged filename
So, we restored our changes
And we can check the difference between current and previous commit
Git diff previouscommitid..currentcommitid
Eg:- git diff 5a9327b..670ade5
If want to go to previous commit
Use this git revert HEAD commitid (which commitid you want to go)
git revert HEAD 5a9327b
its showing the reverted Pluto changes
Sprint1 branch having our changes
If we are working with multiple branches git status will say currently you are in which branch
Observed that we don’t have any pluto file because we reverted pluto changes
If you don’t want to store anything on history use the below command
Git reset –hard commitid
git reset --hard 670ade5
it will remove/delete all history after that (670ade5)commitid
Git ssh login
Check git config
Cat .git/config
This is not a right way to login with git ssh
To login ssh we need to have ssh key
So that generate ssh key using below command
Ssh-keygen.exe
Generated now to look public & private key
Use the command as “ls .ssh”
Copy the public key and put into the github
Open the github and go to settings
Click on that ssh and GPG keys
Click on new ssh key
Give the title like project suitable name and paste only public key and click on add SSH Key
Now added public ssh key
We can going to clone using ssh instead of https
Copied that ssh use that ssh with git clone command
Git clone git@github.com:ManojYajendrababu/titanwork.git
If public key matches with private key, then it will clone successfully
Showing some error due to my system settings
Ssh login is the safer login
Getting below error While trying to push our changes to master/local branch
$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
To resolve this error, follow the below steps: -
To add a new remote, use the git remote add command on the terminal, in the directory your
repository is stored at.
The git remote add command takes two arguments:
A unique remote name, for example, “my_awesome_new_remote_repo”
A remote URL, which you can find on the Source sub-tab of your Git repo
What is meant by git remote
What is the git remote?
The git remote command lets you create, view, and delete connections to other repositories.
Remote connections are more like bookmarks rather than direct links into other repositories.
1. Git remove -v command (view or verify the remote command)
2. Open github
Go to repository and copy the https url
https://github.com/ManojYajendrababu/jenkinstriggers.git
Go to settings->developer settings
Click on the fine-grained tokens
Click on generate new token and do some config and click on generated new token
Once token generated copy that token
github_pat_11A3LKJWQ03bRn3Prv2FQ6_3poeYQs4yMpdMCJFiOWu5KCLlK6KwRbvqau6FcAiCO16G
DSBOHVrQ4PFyOf
3. Run the below command
“git remote set-url origin https://github.com/ManojYajendrababu/jenkinstriggers.git
Edit the above command using the above token
git remote set-url origin
https://github_pat_11A3LKJWQ05KVvAXj2O2NH_uLFXY3UttIvXucyvrBDOFFsoVACc6RkgIjGmoXu
1TFkI3ABIPVXQzq0Z6bo@github.com/ManojYajendrababu/jenkinstriggers.git
4. Git push origin master
Issue is resolved now.
For more info please visit the below link:-
https://www.youtube.com/watch?v=uFaYgSVzy3w