Showing posts with label Git commands. Show all posts
Showing posts with label Git commands. Show all posts

Monday, September 11, 2023

#Git #commands when working with a #Git #repository includes various stages, from setting up the #repository to making changes and collaborating with others. Here's a common #Git #workflow:

 


The typical flow of Git commands when working with a Git repository includes various stages, from setting up the repository to making changes and collaborating with others. Here's a common Git workflow:

1. **Initialize a Repository**:

   - `git init`: Initializes a new Git repository in the current directory.

2. **Clone an Existing Repository** (if not starting from scratch):

   - `git clone <repository_url>`: Clones an existing remote Git repository to your local machine.

3. **Configure Git** (if not already configured):

   - `git config --global user.name "Your Name"`: Sets your name for Git commits.

   - `git config --global user.email "youremail@example.com"`: Sets your email for Git commits.

4. **Check the Status**:

   - `git status`: Shows the status of your working directory, including changes not yet committed.

5. **Stage Changes**:

   - `git add <file>`: Stages specific files for the next commit.

   - `git add .` or `git add --all`: Stages all changes in the current directory.

6. **Commit Changes**:

   - `git commit -m "Your commit message"`: Commits staged changes to the local repository.

7. **Branching**:

   - `git branch`: Lists all branches in the repository.

   - `git branch <branch_name>`: Creates a new branch.

   - `git checkout <branch_name>`: Switches to the specified branch.

   - `git checkout -b <branch_name>`: Creates and switches to a new branch in one command.

8. **Merging**:

   - `git merge <branch_name>`: Merges changes from one branch into the current branch.

9. **Fetching and Pulling Changes** (from a remote repository):

   - `git fetch`: Retrieves changes from a remote repository without merging.

   - `git pull`: Retrieves and merges changes from a remote repository.

10. **Pushing Changes** (to a remote repository):

    - `git push origin <branch_name>`: Pushes local changes to a remote repository.

11. **Viewing Commit History**:

    - `git log`: Shows a detailed commit history.

    - `git log --oneline`: Shows a simplified commit history.

12. **Discard Changes**:

    - `git reset <file>`: Unstages changes for a specific file.

    - `git reset`: Unstages all changes.

    - `git checkout -- <file>`: Discards changes in a specific file.

    - `git reset --hard`: Discards all changes in the working directory.

13. **Resolving Conflicts**:

    - During a merge or rebase, you may encounter conflicts. Resolve them manually, then:

    - `git add <file>`: Mark the resolved file as staged.

    - `git rebase --continue` or `git merge --continue`: Continue the merge or rebase process.

14. **Tagging**:

    - `git tag -a <tag_name> -m "Tag message"`: Create an annotated tag at the current commit.

15. **Removing and Deleting**:

    - `git rm <file>`: Removes a file from the repository and stages the removal.

    - `git mv <old_name> <new_name>`: Renames a file.

    - `git branch -d <branch_name>`: Deletes a branch locally.

    - `git push origin --delete <branch_name>`: Deletes a remote branch.

16. **Stashing Changes**:

    - `git stash save "Stash message"`: Temporarily saves changes that are not ready to be committed.

17. **Pull Requests and Code Review** (GitHub/GitLab/Bitbucket):

    - Create a pull request to propose changes from one branch to another.

    - Review code changes and discuss them with collaborators.

    - Merge the pull request when ready.

18. **Managing Remotes**:

    - `git remote -v`: List remote repositories.

    - `git remote add <name> <url>`: Add a remote repository.

    - `git remote remove <name>`: Remove a remote repository.

    - `git remote set-url <name> <new_url>`: Change the URL of a remote repository.

#Git is a #versioncontrol system that helps you track changes in your code and collaborate with others

https://www.getdbt.com/analytics-engineering/transformation/git-workflow/


### 1. `git init`

- **What it does**: Initializes a new Git repository in your project folder.

- **When to use**: Use it when you start a new project to begin tracking changes.

### 2. `git clone`

- **What it does**: Copies an existing Git repository from a remote server to your local machine.

- **When to use**: Use it to get a copy of a project from a remote server like GitHub.

### 3. `git add`

- **What it does**: Stages changes for commit. It tells Git which files to include in the next commit.

- **When to use**: Use it when you've made changes to your code and want to include those changes in your next commit.

### 4. `git commit`

- **What it does**: Saves your staged changes with a message describing what you did.

- **When to use**: Use it after adding changes with `git add` to create a checkpoint for your work.

### 5. `git status`

- **What it does**: Shows the current state of your repository, including untracked, modified, and staged files.

- **When to use**: Use it to see what's going on in your project before committing changes.

### 6. `git log`

- **What it does**: Displays a history of commits, including who made them and when.

- **When to use**: Use it to review the commit history of your project.

### 7. `git pull`

- **What it does**: Fetches changes from a remote repository (e.g., GitHub) and merges them into your current branch.

- **When to use**: Use it to update your local branch with changes from the remote repository.

### 8. `git push`

- **What it does**: Sends your committed changes to a remote repository (e.g., GitHub).

- **When to use**: Use it to share your work with others by uploading your changes to a remote server.

### 9. `git branch`

- **What it does**: Lists all branches in your repository and shows which branch you're currently on.

- **When to use**: Use it to see what branches exist and to switch between branches.

### 10. `git checkout`

- **What it does**: Switches to a different branch or commit.

- **When to use**: Use it to navigate between different branches or specific points in your project's history.

### 11. `git merge`

- **What it does**: Combines changes from one branch into another.

- **When to use**: Use it when you want to integrate changes from one branch into your current branch.

### 12. `git reset`

- **What it does**: Unstages changes or moves the current branch to a different commit.

- **When to use**: Use it when you need to undo commits or changes that haven't been committed yet.

### 13. `git remote`

- **What it does**: Shows a list of remote repositories (e.g., #GitHub) connected to your local repository.

- **When to use**: Use it to manage remote connections and repositories.

These are some fundamental Git commands that can help you get started with version control. Git can be a bit complex, but as you gain experience, you'll become more comfortable with its features and workflows.

Featured Posts

Kali Linux Remote Desktop: Access GNOME from Windows Using Native RDP

  Kali Linux + GNOME 50 + GNOME Remote Desktop + Windows Remote Desktop (MSTSC) Getting a full GNOME desktop remotely on Kali Linux can be ...