In this tutorial, Git command line for beginners, Git server is a repository. The tutorial I use commands line for my project.
For Gitlab command line for devopsroles.com
Git global setup
git config --global user.name "PHAN VAN HUU" git config --global user.email "pvhuu90@gmail.com"
To create a new my 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 as below
Git current state
How to list which (unstaged) files have changed:
git status
How to list (unstaged) changes to files:
git diff
How to list recent commits:
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 to configure 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 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 understood git command line. Thanks for reading “git command line” my post. I’m updating more useful commands line for git