Debug School

rakesh kumar
rakesh kumar

Posted on

list of gitlab commands

git init: Initialize a new Git repository.

Example: git init
Enter fullscreen mode Exit fullscreen mode

git clone [repository URL]: Clone a remote Git repository.

Example: git clone https://gitlab.com/example/repository.git
Enter fullscreen mode Exit fullscreen mode

git add [file(s)]: Add file(s) to the staging area.

Example: git add file.txt
Enter fullscreen mode Exit fullscreen mode

git commit -m "message": Commit changes to the repository.

Example: git commit -m "Added new feature"
Enter fullscreen mode Exit fullscreen mode

git status: Show the status of the working tree.

Example: git status
Enter fullscreen mode Exit fullscreen mode

git push: Push local changes to a remote repository.

Example: git push origin master
Enter fullscreen mode Exit fullscreen mode

git pull: Fetch and merge changes from a remote repository.

Example: git pull origin master
Enter fullscreen mode Exit fullscreen mode

git branch: List all branches in the repository.

Example: git branch
Enter fullscreen mode Exit fullscreen mode

git branch [branch name]: Create a new branch.

Example: git branch feature-branch
Enter fullscreen mode Exit fullscreen mode

git checkout [branch name]: Switch to a different branch.
Example: git checkout feature-branch

git merge [branch name]: Merge a branch into the current branch.

Example: git merge feature-branch
Enter fullscreen mode Exit fullscreen mode

git diff: Show differences between the working directory and the staging area.

Example: git diff
Enter fullscreen mode Exit fullscreen mode

git log: View commit history.

Example: git log
  git log --oneline
Enter fullscreen mode Exit fullscreen mode

git remote add [name] [URL]: Add a new remote repository.
Example: git remote add origin https://gitlab.com/example/repository.git

git remote -v: List all remote repositories.
Example: git remote -v

git fetch: Fetch changes from a remote repository.
Example: git fetch origin

git reset [file]: Unstage a file.
Example: git reset file.txt

git reset [commit]: Reset the repository to a specific commit.
Example: git reset HEAD~1

git revert [commit]: Revert a commit.
Example: git revert abcdef123456

git stash: Stash changes in a dirty working directory.
Example: git stash

git stash list: List all stashes.
Example: git stash list

git stash apply: Apply the most recent stash.
Example: git stash apply

git stash pop: Apply and remove the most recent stash.
Example: git stash pop

git stash drop: Remove a stash.
Example: git stash drop

git tag: List all tags in the repository.
Example: git tag

git tag [tag name]: Create a new tag.
Example: git tag v1.0.0

git tag -a [tag name] -m "message": Create an annotated tag.
Example: git tag -a v1.0.0 -m "Release version 1.0.0"

git show [tag/commit]: Show information about a specific tag or commit.
Example: git show v1.0.0

git remote remove [name]: Remove a remote repository.
Example: git remote remove origin

git remote rename [old name] [new name]: Rename a remote repository.
Example: git remote rename origin upstream

git clean: Remove untracked files from the working directory.
Example: git clean -f

git cherry-pick [commit]: Apply a specific commit to the current branch.
Example: git cherry-pick abcdef123456

git rebase [branch]: Reapply commits on top of another branch.
Example: git rebase master

git config --global user.name [name]: Set your Git username.
Example: git config --global user.name "John Doe"

git config --global user.email [email]: Set your Git email.
Example: git config --global user.email "johndoe@example.com"

git log --graph: Show commit history in a graph.
Example: git log --graph

git blame [file]: Show who last modified each line of a file.

Example: git blame file.txt
Enter fullscreen mode Exit fullscreen mode

git submodule add [repository URL]: Add a Git submodule.
Example: git submodule add

https://gitlab.com/example/submodule.git
Enter fullscreen mode Exit fullscreen mode

git submodule init: Initialize submodules.
Example: git submodule init

git submodule update: Update submodules to the latest commit.
Example: git submodule update


 git origin -v
  git remote -v
  git pull origin rakesh
  git branch
  git checkout -b rakesh
  git branch
  git pull origin rakesh
  git pull origin rakesh --allow-unrelated-histories
  git log --oneline
git branch
 git push origin rakesh
 git pull origin new-develop
Enter fullscreen mode Exit fullscreen mode

push your code from a local repository to a remote repository

branch on GitLab, you can follow these steps:

Initialize the Git repository:
If you haven't already done so, navigate to your local repository directory in the terminal and run the following command to initialize a Git repository:

git init
Enter fullscreen mode Exit fullscreen mode

Add and commit your changes:
Use the following commands to add the files you want to commit and create a commit with a descriptive message:

git add .
git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode

Add the remote repository:
To specify the remote repository URL, run the following command:

git remote add origin <remote_repository_url>
Enter fullscreen mode Exit fullscreen mode

Replace with the URL of your remote repository on GitLab.

Push the code to the remote repository:
To push your local repository's branch to the remote repository, use the following command:

git push origin <local_branch_name>:<remote_branch_name>
Enter fullscreen mode Exit fullscreen mode

Replace with the name of your local branch and with the name of the branch you want to push to on the remote repository.

Here's an example:
Let's say you have a local branch named "feature-branch" that you want to push to the "main" branch on your remote repository on GitLab. The commands would look like this:

git add .
git commit -m "Adding new feature"
git remote add origin https://gitlab.com/your-username/your-remote-repo.git
git push origin feature-branch:main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)