In this tutorial, the Git command line is for beginners, Git server is a repository. I use the command line for my project.
Git is a powerful version control system used for tracking changes in software projects. Here are some basic Git commands for beginners:
Table of Contents
Git command line for beginners
Git global setup
git config --global user.name "PHAN VAN HUU" git config --global user.email "pvhuu90@gmail.com"
To create a new repository
cd BashScripts git clone https://gitlab.com/huupv/DevopsSkills.git touch README.md git add README.md git commit -m "add README" git push -u origin master
Existing my folder
cd BashScripts git init git remote add origin https://gitlab.com/huupv/DevopsSkills.git git add . git commit -m "Initial commit" git push -u origin master -f
Existing git my repository
cd BashScripts git remote rename origin old-origin git remote add origin https://gitlab.com/huupv/DevopsSkills.git git push -u origin --all git push -u origin --tags
I explained the commands below
Git current state
How to list which (unstaged) files have changed, Shows the current status of the repository, including modified and untracked files.
git status
How to list (unstaged) changes to files: (Shows the differences between the working directory and the staging area)
git diff
How to list recent commits: (Displays the commit history of the repository)
git log
Tell me who you are:
git config --global user.name "PHAN VAN HUU" git config --global user.email "pvhuu90@gmail.com"
To create a new local repository:
git init
To check out a repository
To create a working copy of a local repository
git clone https://gitlab.com/huupv/DevopsSkills.git
For remote server
git clone huupv@host:/path/to/repository
How to add files:
git add File_Name
To commit change but not yet to the remote repository:
git commit -m "Add file to repository commit"
To commit any file with git add:
git commit -a
How to “push” send changes to the master branch of your remote repository:
git push origin master
How to connect to a remote repository:
git remote add origin https://gitlab.com/huupv/BashScripts.git
How to list all currently configured remote repositories:
git remote -v
For Git branches
To create a new branch and switch to it:
git checkout -b <branchname>
To switch from one branch to another:
git checkout <branchname>
To list all the branches in your repository:
git branch
To delete the branch:
git branch -d <branchname>
To push all branches to your remote repository:
git push --all origin
To delete a branch on your remote repository:
git push origin :<branchname>
How to fetch and merge changes on the remote server to your working directory:
git pull
The conclusion
Thought the article, To help you understand the git command line. Thanks for reading my “git command line” post. I’m updating more useful commands line for Git. Thank you for reading the DevopsRoles page!