Tuesday, March 29, 2022

Git Commands

Command for git






Step 1:- We have three branches:-

 Master

 feature-a 

 feature-b

Now we are in the Master branch.


Step 2:- How to change the branch Master to Feature

git checkout feature-a 


Step 3:- How to merge the branch Feature-a to Master

Now we are in the feature branch so we have changed the branch

  •  git checkout master

Now we are in the master branch

  • git merge feature-a





Step 3:- How to create and switch the branch

Now we are in the Master branch so switch and create the branch.

  •  git checkout -b feature-c



Step 4:- How to check git all commit

  •  git log --oneline

Step 5:- How do I connect a local folder to an existing github repo?

  • git init
# Add files

  • git add .
# Commit your changes

  • git commit -m "First commit"
# Add remote origin

  • git remote add origin <Remote repository URL>
# <Remote repository URL> looks like: https://github.com/user/repo.git
# Verifies the new remote URL

  • git remote -v
# Push your changes

  • git push origin master


How do I resolve git saying "Commit your changes or stash them before you can merge"? 



git stash

git pull <remote name> <remote branch name> (or) switch branch

git stash apply --index

The first command stores your changes temporarily in the stash and removes them from the working directory.

The second command switches branches.

The third command restores the changes which you have stored in the stash (the --index option is useful to make sure that staged files are still staged).

Showing diff of a commit id:- 

Step 1:- Run git log to view some recent commit ids. 


Step2:- 
Run the following command for view diff for a commit id (0040d2082dc58b015267eb7c5b29583873200ed3).
 
$ git diff commit-id^!
for example:- $ git diff 0040d2082dc58b015267eb7c5b29583873200ed3^!


No comments:

Post a Comment

If you have any problem please let me know.