Git and GitHub...

Git and GitHub...

Login aws account----> create two EC2 instance

Commands:-

  • sudo su #for admin command
  • apt-get update -y #to update ubuntu machine
  • apt-get install git -y # To install git in ubuntu machine
  • git --version #To know the git version
  • git config --global user.name "xyz "
  • git config --global user.email " [email protected] "
  • git config --list # to check the list that all things are done properly
  • which git #To know git is installed or not

How to commit, push & pull from GitHub:-

Practical scenario with aws account:

create two instance (machine) in two region (Mumbai & another in Singapore)

  • Now login into Mumbai region EC2 instance
  • create one directory and go inside it
  • run the command git init #To initialize the directory we run this command, After run this we get .git folder
  • touch file1 #create a file and put some data in
  • git status #To check the status
  • git add #This command is use to add the file after completion of our work into staging area.
  • git commit -m "1st commit from mumbai" # This command helps to commit the file from staging area to local repo
  • git status #after commit the file, again check the status of git
  • git log #To check the commit info
  • git show <commit id> #here no need to put 40digit of commit id, we can use starting few characters of commit id
  • git remote add origin <central git url> #central git (github url)
  • git push -u origin master #By default branch id master(enter username and password)

Same process we have to do on another region EC2 instance.

or.. now go to Singapore EC2 instance create one directory and go inside it.

and run command mentioned below...

  • git init
  • git remote add origin <git hub repo url>
  • git pull -u origin master
  • git log
  • git show <commit id>

Now add some code in the file and do the below process.

  • git status # check the status after doing the modification in the file
  • git add # add the file in staging area
  • git commit -m "Singapore update1"
  • git status
  • git log
  • git push origin master

Ignore Some Files:-

To ignore some files while commit. create one hidden file .gitignore and enter file format which you want to ignore.

for example:

vi .gitignore

enter{*.css

*.java

  • git add .gitignore
  • git commit -m "latest update exclude .css"
  • git status

create some text, java & css files and add them by running "git add"

Branch:

git branch

#The diagram above visualizes a repository with more than one isolated lines of developments. One for a small features and one for big feature, by developing them in parallel but it also keeps the main master branch free from error.

  • each task has one separate branch
  • After done with code, merge other branches with master.
  • this concept is useful for parallel development
  • you can create any number of branches
  • change are personal to that particular branch
  • default branch is master
  • file created in workspace will be visible in any of the branch workspace will you commit .once you commit, then that files belong to that particular branch.
  • When created new branch, data of existing branch is copied to new branch.

Commands:

  • git branch # To see the list of available branch

o/p--> master ( means current branch)

  • git branch <branch name> # To create a new branch
  • git checkout <name of the branch in which we want to switch> # To switch branch
  • git log --oneline #To see what commit in our space
  • git branch -d branch1 #to delete the branch1

Merge:

  • you can't merge branches of different repo.
  • we use pulling mechanism to merge branches.
  • git merge <branch name>

Git conflict:

when some file having different content in different branches, if you want to merge then conflict occurs(resolve conflict then add and commit)

Git stashing:

Suppose you are implementing a new feature for your product. your code is in progress and suddenly a customer escalation comes because of this you have to keep aside your new feature work for few hours.

you can't commit your partial code and also can not throw away your changes, so you need some temporary storage, when you can store your partial changes and later on commit it.

to stash an item (only applies to modified files not new files)

Commands:

git status # to stash an item

git stash list # to see stashed item list

Git reset:

git reset is a powerful command that is used to undo local changes to the state of git repo

To reset staging area

git reset <file name>

git reset. # reset all files

To reset the changes from both staging area and working directory at a time.

git reset --hard



要查看或添加评论,请登录

Rakesh Kumar的更多文章

  • Docker...

    Docker...

    Container: A container is a standard unit of software that packages up code and all its dependencies so the application…

  • Docker..

    Docker..

    What is container? A container is a standard unit of software that packages up code and all its dependencies so the…

  • GIT and GitHub....

    GIT and GitHub....

    Version control system Stages of git/workflow Stages of git and its terminology Introduction: It is the software…

  • Interactive file and explorer

    Interactive file and explorer

    description:- we will create a bash script that serves as an interactive file and directory explorer. The script will…

  • Basic of bash scripting

    Basic of bash scripting

    Here we will cover the basics of bash scripting. Task1:Comments In bash scripts, comments are used to add explanatory…

社区洞察

其他会员也浏览了