Essential Git Commands Every Engineers Should Know

Git is one of the most popular version control systems used by software developers today. It allows teams to work collaboratively on a proje...


Git is one of the most popular version control systems used by software developers today. It allows teams to work collaboratively on a project, keep track of changes, and manage versions of their code. Git has a command-line interface (CLI) that can seem intimidating at first, but once you master the basics, you can accomplish a lot more with Git.

In this article, let’s take a look at the Git commands you should know to master Git CLI, these commands cover the most useful Git commands that are often used.

1. git init  -- git initialize
        The commands turn the empty directory into an empty git repository.
Command: git init
I am using the git bash in the windows.



2. git config -- git configuration            The Git config command is used to address the name and email of the user to commit the code from the local machine to the remote branch, In this method, we can identify the committed user name in the GitHub Commands: git config --global user.name “username” git config --global user.email “email address” --global option used for global configuration. 3. git clone: Cloning the git remote repository to the local machine. command: git clone git repo URL Example: git clone git@github.com:techieview/techiev-devopsclass.git where git@github.com:techieview/techiev-devopsclass.git is a git repository URL

4. git remote: It is used to add the remote repository(GitHub) to my local machine. Command: git remote add origin “git URL”

5. git add:                   In this command, add the files to the staging area of the git.  In git, before committing to GitHub you need to add the files using the git add command. Command:  git add filename                 Adding the particular file for the commit                 git add .                 Adding all the files and folders inside the directory

6. git status:                 This command is used to check the current state of the local branch                 If any files are updated or changed, it will show the file. So if we want to commit the changes or else stash the changes                 If there were no changes in the files, return the messages like nothing to commit, and the working directory is clean  command: git status


7. git diff The git diff command is used to show the difference between edited files. Command: git diff filename

8. git commit:
                Commit the local branch files to the remote branch(GitHub repository)
                For the commit changes always use a short message.
Command: git commit -m “message”


9. git push:                  Pushing the committed codes from the local to the remote branch or GitHub repository. Command: git push

10. git pull:                 Pulling the updated code from the remote branch to the local branch.  Command: git pull


10. git branch: This command is used to check the current working branch as well as all the branches. Command: git branch (a) Creating a new branch Type1: git branch branch name Type2: git checkout -b branch name The above two commands are used to create the branch in the local repo.

(b) Switching to another branch Command: git checkout branch name git checkout is used to checkout or switch the branches.

(c) Delete the particular branch
    Command: git branch -d branchname
The -D option to delete branches without asking for any prompt.
    Command: git branch -D branch name
If any unmerged changes in the current branch will be lost using the -D option.

11. Rename the branch 

     Command: git branch -m techiev

12. git merge:
        Merging the files from one branch to another branch.
command: git merge branch name 

13. git fetch: 
                The git fetch command is used to retrieve the latest metadata info from the original
 command: git fetch

Advanced git commands:

1. git stash: 
                  To save the changes into the local branches, but code changes do not move into the remote branch(Github branch), and also working tree needed to be cleaned, for all the above needs to be done using the git stash command.
command: git stash -u 
Check the git stash status to see whether the current working directory is clean or not.
     command: git status
List the modification of the stash files
     command: git stash list 
Inspect the stash files
     Command: git stash show
Now we want to commit the stash code into the remote branch means need to revert the stash using the below command.
   Command: git stash apply
After the revering stash now we can commit the code.

2. git log: 
               It will show the commit history.
Command: git log

Options:
             git log --before = “data frame”
It will give the logs for the given data frame.
             git log --author = “name”
It will give the logs of the commit history for the particular author.
            git log --oneline
It will give the logs for the last commit.

 3. git revert: 
                  This command is used to revert back to the previous version of the file.
To revert need to check the last commit log so use the below command
command: git log --oneline

Now note the last commit ID and use that ID to revert the commit using the below command.
Command: git revert last commit id. 

command: git revert HEAD

----------------------------------------!!!! Happy Learning with Techiev !!!!!!!!----------------------------------

-------------------------Subscribe our Youtube Channel by clicking the below link---------------------- ----------------------------!!https://www.youtube.com/@techieview729!!---------------------


Name

AWS,19,CNCF,8,Devops,37,linux,11,
ltr
item
Techie View: Essential Git Commands Every Engineers Should Know
Essential Git Commands Every Engineers Should Know
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAD94rlsJ6BdsmdtMkaAecBtZl6tpgCrfjeKopAHv_wA11ObTg-v8ru8eARoevDs26wtBaqTFz9yMNI1qTRYXWB-F7kVLmILzA-5J4bKTbs1BVhQtPDl9dqpXsfrVXNI-QKW9cyUiY6GzzlpUZY2aBv_KI3vei3S6QGeUWJCjaA6hXRF5rJtxCRSgpxqP2/w640-h360/Git.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAD94rlsJ6BdsmdtMkaAecBtZl6tpgCrfjeKopAHv_wA11ObTg-v8ru8eARoevDs26wtBaqTFz9yMNI1qTRYXWB-F7kVLmILzA-5J4bKTbs1BVhQtPDl9dqpXsfrVXNI-QKW9cyUiY6GzzlpUZY2aBv_KI3vei3S6QGeUWJCjaA6hXRF5rJtxCRSgpxqP2/s72-w640-c-h360/Git.png
Techie View
https://www.techiev.com/2024/10/essential-git-commands-every-engineers.html
https://www.techiev.com/
https://www.techiev.com/
https://www.techiev.com/2024/10/essential-git-commands-every-engineers.html
true
7013663511659419322
UTF-8
Loaded All Posts Not found any posts VIEW ALL View Full Article Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy