How to use Git and Take Git Pull and Git Push and Install The Git On The Local Machine In Windows.

Sasiclinton
9 min readApr 5, 2024

--

I’ve explained All Git Commands for instal and take pull and push your code.

Step 1:-

Download Git for Windows:
Go to the official Git website: https://git-scm.com/downloads Click on the inside downloads “Windows” button.
Next page you have choice 32 or 64 bit : (https://git-scm.com/download/win) based on your machine. This will automatically download the latest version of Git for Windows.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 2:-

Run the Installer: Once the download is complete, locate the downloaded file (typically named Git-<version>-64-bit.exe or similar) and double-click on it to run the installer.

Once you have configured the installation settings, click on the “Install” button to start the installation process. Wait for the installation to complete.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 3:-

Verify Installation: After the installation is finished, you can verify that Git has been installed correctly by opening a command prompt and typing:

git — version

This command should display the installed version of Git.

Once installed git without error then follow the below step’s.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 4:-

Once Git is installed, you can start using it from the command line to manage your code repositories.

Navigate to Your Project Directory: Open a terminal or command prompt and navigate to the directory where you want to create your Git repository.

Initialize the Git Repository: Run the following command to initialize a new Git repository:

git init

This command will create a new hidden directory named .git in your project directory, which is where Git stores all the information about your repository.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 5:-

The command git remote add origin <remote_repository_URL> is used in Git to add a remote repository to your local Git repository.

  • git remote: This is the Git command for managing remote repositories.
  • add: This subcommand is used to add a new remote repository.
  • origin: This is a common convention for naming the default remote repository. It's just a label and can be replaced with any name you prefer.
  • <remote_repository_URL>: This is the URL of the remote repository you want to add. It typically points to a repository hosted on a service like GitHub, GitLab, Bitbucket, etc.
  • In this example, we’re adding a remote repository located at https://github.com/username/repository.git, and we're labeling it as origin.

git remote add origin <remote_repository_URL>

  • Once you’ve added a remote repository, you can use other Git commands like git push, git pull, and git fetch to interact with the remote repository, such as pushing your local changes to the remote or pulling changes from the remote to your local repository.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 6:-

Overall, git fetch is a useful command for keeping your local repository up-to-date with changes from a remote repository while giving you control over when to integrate those changes into your local branches and also can see available branches.

Retrieving Changes: When you run git fetch, Git will contact the remote repository specified by the remote's URL (e.g., origin) and fetch any new commits or branches that exist on the remote but not in your local repository.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 7:-

The git branch -M main command is used to rename the current branch to main. This command is commonly used when transitioning from using the default branch name master to main, which is a common practice to promote inclusive language and remove any potentially offensive terminology.

Here’s what each part of the command does:

  • git branch: This is the Git command used for working with branches.
  • -M: This is a shorthand option for specifying that you want to rename the current branch, regardless of whether it exists or not. The -M option stands for "move/rename" and is commonly used with branch-related commands.
  • main: This is the new name you want to give to the current branch. In this case, you're renaming the current branch to main.

So, when you run git branch -M main, Git will rename the current branch to main. This command is typically used when you've created a new repository or want to rename an existing branch to main as part of the transition from using master as the default branch name.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 8:-

Add Your Files to the Repository: Start adding files to your project directory, or if you already have files, you can add them to the repository using the git add command. For example, to add all files in the current directory, you can use:

git add .
which means it adding current directory all files.

(or)

git add <file_name> it only adding particular file only.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 9:-

Commit Your Changes: Once you’ve added the files you want to include in the initial commit, you can commit them to the repository using the git commit command:

git commit -m “Initial commit”

(or)

git commit -m “<Put_your_own_message>”

Continue Working and Making Commits: Now that you’ve initialized your Git repository and made your initial commit, you can continue working on your project, making changes, and committing them as needed using git add and git commit.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 10:-

While commit our changes then through the any Authentication error follow these steps'.

git config — global user.email “your_gitlab_email@gmail.com

(or)

git config — global user.name “your_gitlab_user_name”

You don’t get any error ignore this steps.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 11:-

The committed changes in your local repository to the remote repository specified by <remote_name>. It updates the remote branch specified by <branch_name> with your changes.

git push <remote_name> <branch_name>

git push origin <dev_branch

(or)

git push -f origin main

(or)

git push -uf origin main

  • git push: This command is used to send local commits to a remote repository.
  • -u: This option sets up tracking between the local branch (main in this case) and the remote branch (main on the origin remote). It is short for --set-upstream.
  • -f: This option stands for "force" and it tells Git to force-push the local branch to the remote repository, overwriting any changes on the remote branch with the local commits.
  • origin: This is the name of the remote repository. In this case, it refers to the default name often given to the remote repository you cloned from or added using git remote add.
  • main: This is the name of the local branch you want to push to the remote repository.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 12:-

Fetches changes from a remote repository and integrates them into the local repository.

The remote repository specified by <remote_name> and merges them into the current branch in your local repository. It's equivalent to running git fetch followed by git merge.

git pull <remote_name> <branch_name>

git pull origin dev_branch

While fetching changes from the remote repository, if someone has made conflicting changes, you need to resolve the conflict before merging.

Another one way:-

Copies an existing Git repository from a remote source to your local machine.

git clone <repository_URL> [directory]

Downloads the entire repository from the specified URL (e.g., GitHub, GitLab) and creates a new directory (optionally specified) containing the repository files. This command establishes a connection between your local repository and the remote repository.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 13:-

Check anything changes in working directory and the staging area.

git status

Shows which files are modified, staged, or untracked in the working directory. It provides information about the current branch and any changes that need to be committed or pushed.

The above commands we use common commands.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 14:-

The git checkout command is used to switch branches or restore files in the working directory to a specific state.

  • To switch branches: git checkout <branch_name>
  • To restore files to a specific state (discard changes): git checkout -- <file(s)>
  • When used to switch branches, git checkout updates the working directory to reflect the state of the specified branch.
  • When used to restore files, git checkout replaces the contents of the specified files in the working directory with the contents from the last committed state. This effectively discards any changes made to those files since the last commit.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 15:-

The git reset command is used to reset the current branch to a specific state (commit), typically used for undoing commits or moving the HEAD to a different commit.

  • To reset the current branch to a specific commit (soft reset): git reset --soft <commit>
  • To reset the index and the working directory to a specific commit (mixed reset): git reset --mixed <commit>
  • To reset the index, the working directory, and discard changes (hard reset): git reset --hard <commit>
  • git reset --soft moves the HEAD to the specified commit, but leaves the changes staged in the index and the working directory unchanged.
  • git reset --mixed moves the HEAD to the specified commit and resets the staging area (index) to match that commit, but leaves the changes in the working directory unchanged.
  • git reset --hard moves the HEAD to the specified commit and resets both the staging area and the working directory to match that commit, discarding any changes made since then.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Step 16:-

The git revert command is used to create a new commit that undoes the changes made by a specific commit.

git revert <commit>

Creates a new commit that undoes the changes introduced by the specified commit, effectively reverting the repository’s state back to the state before the specified commit was made. This command does not modify the commit history; instead, it adds new commits to undo the changes.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Author by:-
SasiClinton.R (profile)

--

--

No responses yet