Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 24, 2020 06:03 pm GMT

Swing with git basic

Draw your git sword

Note- will start with the understanding of git commands

  • To see present origin repo

    git remote -v

  • To add origin

    git remote add origin --remote repo URL--

  • origin can be named anything but it should be remembered by you for future references

  • to set a new remote origin --remote repo url--

    git remote set-url origin --remote repo url--

Notes

  • set commit username (it sets globally, please change it if you want to change your name in other commits)> git config --global user.name "Abhishek Sharma"
  • set commit email

    git config --global user.email "[email protected]"

  • set user name in the previous commit if it is from another user name, it will open in vi editor press i to insert words; to save it press- ESC ":wq" or to save without an edit press :q

    git commit --amend --author="Abhishek Sharma [email protected]"

Kneel before git

  • to clone a repo

git clone --remote repo url--

branch creation

  • to create a new branch

    git checkout -b branchname
    git checkout -b branchname-1

  • to switch branch from one to another (presently the branch is branchname-1)

    git checkout branchname

  • to track changes (it will show modified files)

    git status

  • to add a specific file

    git add filename, filename2

  • to add all files at once

    git add .

  • to commit on your local repo

    git commit -m "commit message"

  • to push changes on origin

    git push origin branchname

  • Checkout to another branch to merge the changes in the branch

    git checkout branchname-2

  • before the merge, we will take the latest pull from this remote branchname-2

    git pull origin master

  • now merge the branchname into branchname-2

    git merge branchname-2

  • push changes back to the master branch

    git push origin branchame-2

branch deletion

  • delete the branch from the local system > git branch -d branchname
  • delete the branch from a remote system > git push origin --delete branchname

git never forgets, it will help others to find your mistake and they blame you

  • details> git log
  • onliner details > git log --oneline

Commit details

  • It will show you changes of a specific commit

git show commitID (hashcode)
e.g. git show 785767e

  • it points to the latest commit

git show HEAD

  • to see head to the previous commit

git show HEAD~1

  • to previous to the previous commit

git show HEAD~2

Let understand the real git process in the companies with an example-

  • create a GitHub account or log in to your account
  • Create a repo "git-basic" in your git account

  • create a repo in the local system

    mkdir git-basic
    cd git-basic

We have only one branch -master for this repo

  • create a branch dev

git checkout -b dev

  • create a file named as git-basic

touch git-basic.txt

  • create write in file - "I am git ninja" and save (ctrl+s or cmd +s) this files

  • check this file to track the changes

git status

  • the git-basic file is not staged right now, so we will add the file in the stage area

git add git-basic.txt

  • we will commit the changes

git commit -a "first git commit"

  • now checkout to master branch to merge the changes

git checkout master

  • add remote repo (Github account repo)

git remote add origin -- remote repo url--

  • pull the latest update from the origin in this branch

git pull origin master

  • its time to merge the dev branch in master

git merge dev

  • push the changes in the remote directory

git push origin master

** Hope, you like my post!**

Thanks,
Abhishek Sharma


Original Link: https://dev.to/imabtiwari/swing-with-git-basic-34fp

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To