20.9.22

GIT commands

 Working Directory:-

  • Project folder resides in your system.
  • It may or may not be tracked by Git.
  • Git tracking is initiated by "git init", it automatically creates a hidden .git folder.

Staging Area:-

  • Once you are in working directory , we have to specify which files are to be/not tracked by mentioning in the gitignore.
  • Some of the temp files need to be ignored which don't need to be tracking.
  • To add files into staging area, we "git add".

Commit:-   

  • Once files are moved into staging , we can commit them to repo, until it's not commited to git its not saved in repo.
  • "git commit -m "code change message".
  • Commit id will be generated once you commit any thing, to manage versioning.


Github:-

  • Once code is committed to your local repo, we need to publish it to remote server.
  • "git push"
  • commit id will help in revert the code to previous version.
  • A pointer to latest commit is called HEAD.


Master branch & Feature Branch.



git setup in GCP, Ubuntu instance:-

  • check if git is already exists?  git --version.
  • "mkdir  git_demo" : create a folder for repo.
  • ls -ltr and ls -ltra(hidden files)
  • run "git init" to track changes in this folder
  • "ls -ltra"
  • "ls -ltr .git"
  • "cat .git/HEAD" will show the head pointer.
  • "git status" to track/see the changes in repo.
  • "git add ."  this add all the files in the current directory to tracking, "." mean current directory files, no hidden files will be added for tracking.
  • "git rm --cached <file>..." to unstage/remove files.
  • "git config --global user.email xyz@gmail.com"
  • "git_demo$ git config --global user.name xyz"
  • "git remote add origin https://github.com/xyz/GitRemoteRepoTest.git"
  • "git push"
  • "git push origin master". enter username"xyz" and personal access token.
  • Refer:- https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

Cloning a Repo:- 
  • Go to github and copy the url for clone "https://github.com/xyz/GitRemoteRepoTest.git"
  • "git clone https://github.com/xyz/GitRemoteRepoTest.git" run this command in new folder for creating the git repo.
  • git pull https://github.com/xyz/GitRemoteRepoTest.git ( to pull updated changes from repo).
GIT Branching:-

  • "Git branch <anybranch name>".      to create new branch
  • git branch.                                          to list the branches
  • git checkout <newbranch name>.    this will make HEAD point to new branch.
  • git log --graph --pretty=oneline
GIT STASH:-

git stash -u
git stash pop

GIT REVERT:-

git revert <commit id>

GIT DIFF:- To find difference between two versions of the file.

git diff <commit id>


MERGING BRANCHES:-

Git Merge:

git merge <source branch name/feature branch name>    run this cmd from the master branch.

Git Rebase:

It's more used to get the latest master branch code to feature branch, once after the feature branch code is tested and merged into master branch.  it helps the feature branch to rebase the latest code from master.

1. "git checkout <featurebranch name>"      2. "git rebase master"






No comments:

Post a Comment