02. Basic Git Command part 01

 Basic Git Command part 01


git->bitBucket | git->gitHub | git->gitLab


Read for more info https://git-scm.com/docs




 

CONFIG GIT

Read for more info 

https://adamtheautomator.com/git-bash/


Downloading and Installing Git (Bash)

https://gitforwindows.org/

Run the git command below to verify Git Bash is installed and its current version (--version).

git --version 

1. Launch Git Bash console by clicking on the Start button, type git, and click on Git Bash.

2. Run the below git config command to add your name (YourName) as your git username (user.name). The git config command administers configuration variables that control how Git looks and operates.

Pass the --global option to the git config command to define the configuration variable (YourName) in the ~/.gitconfig file specifically.

git config --global user.name "YourName" 

3. Now open the command prompt and run the below git config command to add your email ("TestEmail@mail.com") as your git user email (--global user.email) in the ~/.gitconfig file.

git config --global user.email "TestEmail@mail.com" 

4. In the same command prompt window, run the below git config command to list (--list) all the configuration variables in Git.

git config --list 

You can see below that even though you’ve added variables in the ~/.gitconfig file via different consoles, the variables are accessible and displayed in the command prompt.


git config --get remote.origin.url - get repository URL

git remote set-url origin <url> - change the repository URL


git init - Initializing git repository

git clone <url> - get a clone

git branch -r - check remote branches

git branch  - show current branches in local

git fetch - get remote host (gitHub) changes to local

git merge <branch-name> - merge changes to current branch from given branch

git pull <url> - get the update from the remote <branch-name> and merge to local branch(=git fetch + git merge)

git status - check the change file list

git diff <branch-name>- check the file changes with master branch

git log - used to view the history of committed changes within a Git repository

 

git checkout <branch_name> - switch between branches

git checkout develop -- helm\demo.values.yaml

git checkout -b <new_branch_name> - checkout new branch(going to inside to branch,git checkout -b dev master - create new dev branch using master branch)

git add file1.java file2.java -  (First need to stage the files which has changes. Ex: git add Test1.java Test2.java Test3.java)

git add * - Add all files to stage

git commit -m "commit_message" - Ex: git commit -m "TEST-1234 updated the configs" //After staging you can commit the changes

git push origin <branch_name> - Ex: git push origin TEST-1234 //After commit the changes, you can push the changes to remote repository

 

MERGING CHANGES.

01. If we are in a sub branch(feature branch), first need to get the update for the Origin branch. Then merge the origin branch to sub branch(current working branch)

Ex: git checkout master //switch to master branch from current branch

    git pull origin //get the update for master branch

git checkout TEST-1234 //checkout again to current working branch

git merge master //merge the master branch to current branch

 

STASH CHANGES.

01.If we are in a sub branch (Ex: current working branch TEST-1234), If we want to switch to another branch. First stash the changes(save in local memory)

git stash - Remove changes from branch to memory

git stash save "stash-message"  // this will save all the local changes you have done after the last commit.

git checkout TEST-5678 //switeched to another branch

 

List already stash changes

git stash list  // this will show you a list of stash changes you have already completed.

 

Result of previous commnds looks like below

stash@{0}: WIP on master: d7435644 Feat: configure graphql endpoint

stash@{1}: WIP on master: d7435643 check confige

stash@{2}: WIP on master: d7435644 abc: testing

stash@{3}: WIP on master: d7435644 cdkkk: check

 

If you want to apply a previous change you have saved as stash then execute below commands

git stash apply stash@{1}

If you want to see the changes in a specific stash use below commands

git stash show stash@{1}

 

git merge -s recursive -X  ignore-all-space <branch> - go to required branch first and then merge

Ex : go to master branch, - git merge -s recursive -X ignore-all-space secure_fund_v1.0 (merge secure_fund_v1.0 branch to master)

git reset --hard HEAD - remove newly updated changes from local

git show <commit id> - to get the details of a commit

  

GIT TAG

git tag - Listing the existing tags in Git 

git tag -l "v1.8.5*" -  If you’re interested only in looking at the 1.8.5 series, you can run this.

git tag -a v1.4 -m "my version 1.4" - Creating an annotated tag in Git

git show v1.4 - You can see the tag data

git push origin <tag_name> - tag push to server.

git push origin --tags - If you have a lot of tags that you want to push up at once, you can also use the --tags option to the git push command.


DELETE

git tag -d <tagname> - To delete a tag on your local repository.

To delete a remote tag.

01.git tag -d <tagname> AND THEN RUN git push origin :refs/tags/<tagname>

                            OR

02.git push origin --delete <tagname> - Delete a remote tag.

 

RESET

git reset

git reset --hard HEAD - resets the current branch tip, and also deletes any changes in the working directory and staging area. Therefore, it resets index entries to the state of the specified commit.

 reset --soft HEAD~1 - undoes all the changes made between where HEAD was pointing and the specified commit, and saves all the changes in the index. In other words, Git re-adds the changes as staged, ready to be committed again.

git reset HEAD`1 -  git reset changes where the current branch is pointing to ( HEAD ). HEAD is a pointer or a reference to the last commit in the current branch. HEAD~3 would mean behind three commits from HEAD.

git reset <commit-id> - This will roll back the repository state as before commit <commit-id>.Commit Id can be taken from git log.

git reset --hard origin/<branch> - throw away all my staged and unstaged changes, forget everything on my current local branch and make it exactly the same as origin/master.

 

DELETE

git branch -d <branch_name>  -  delete local branch

git branch -D <branch_name>  -  delete local branch(without asking  any confirmation)

git push -d origin <branch_name>  - delete remote branch

  

REDABSE

Process of integrating changes from one branch onto another. Rebasing is the process of combining or moving a sequence of commits on top of a new base commit. Git rebase is the linear process of merging.

 

after a rebase - check working tree is clean using "git status" then run

git push --force

git log --pretty=oneline

 

CHERRY PICK

 

git cherry-pick [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff] [-S[<keyid>]] <commit>…​

git cherry-pick (--continue | --skip | --abort | --quit)

Read for more info https://git-scm.com/docs/git-cherry-pick

Comments

Popular posts from this blog

02. Spring – Creating spring project clone it with GIT step by step.

02.What is MicroService?

06.Mongo DB - Query part 2 (Aggregation)