Git Basic Workflow Commands

G

Prerequisites:

After Installing Git in your Computer, Open an GitHub account with Username and Password.

In the Git bash, give the following command:

  • Git Config:

Git config –user.name “1stop4homebuyers”

Git config –user.email “office@1stop4homebuyers.co.uk”

This command sets the author name and email address respectively to be used with your commits.

Do the following to create a new repository:

To create a new repository, give a repository name and initialize a readme file.

After creating a new repository called Property in git hub, Clone the repository into your local system.

Open a browser and a terminal window from your desktop. After opening the terminal window, do the following:

Navigate to your home (~) directory.

$ cd ~

As you use Github more, you will probably work in multiple repositories. For that reason, it’s a good idea to create a directory to contain all those repositories.

Create a directory to contain your repositories.

$ mkdir repos

From the terminal, update the directory you want to work in to your new repos directory.

$ cd ~/repos
 

From Github, go to your Property repository and select Clone this repository.

Github displays a pop-up clone dialog. By default, the clone dialog sets the protocol to HTTPS or SSH, depending on your settings.

Copy the highlighted clone command.

From your terminal window, paste the command you copied from Github and press Return.

In the git terminal, give the git clone command.

  • Git clone [url]

List the contents of your repos directory and you should see your Property directory in it.

So, we successfully cloned your repository to your local repository.

Add a file to your local repository and put it on Github:

Go to your terminal window and navigate to the top level of your local repository.

Enter the following line into your terminal window to create a new file with content.

List all the file in Property directory by using command ls

Get the status of your local repository. The git status command tells you about how your project is progressing in comparison to your Github repository.

At this point, Git is aware that you created a new file, and you’ll see something like this:

The file is untracked, meaning that Git sees a file not part of a previous commit. The status output also shows you the next step: adding the file.

Tell Git to track your new locations.txt file using the git add command. Just like when you created a file, the git add command doesn’t return anything when you enter it correctly.

The git add command moves changes from the working directory to the Git staging area. The staging area is where you prepare a snapshot of a set of changes before committing them to the official history.

Issue the git commit command with a commit message, as shown on the next line. The -m indicates that a commit message follows.

The git commit takes the staged snapshot and commits it to the project history. Combined with git add, this process defines the basic workflow for all Git users.

Up until this point, everything you have done is on your local system and invisible to your Github repository until you push those changes.

Go back to your local terminal window and send your committed changes to Github using 

git push origin Master. This command specifies that you are pushing to the master branch (the branch on Github) on origin (the Github server).

Your commits are now on the remote repository (origin).

Go to your Property repository on Github. If you click Commits in the sidebar, you’ll see a single commit on your repository. Github combines all the things you just did into that commit and shows it to you.

Pull changes from your Git repository on Github 

Step 1. Create a file in Github

To add your new locations file, do the following:

  1. From your Property repository, click Source to open the source directory. Notice you only have two files, locations.txt and README in your directory.

Create a new file called Estate Agent and commit changes by commit Button.

So new file is formed in Property Repository. You need to pull that file to the local repository by doing following:

1.Open your terminal window and navigate to the top level repository.

2.Enter the git pull  –all command to pull all the changes from github

The git pull command merges the file from your remote repository (Bitbucket) into your local repository with a single command.

Navigate to your repository folder on your local system and you’ll see the file you just added.

Fantastic, pull command pulled the estate agent file to the local repository.

Important Git commands

  1. To see on which branch git is and the status of the branch changes.
git status

2. To push the changes to staging area from the working directory after the changes to it.

git add "file_name"

3. After add command to push the changes to local repository, use commit command as below to push the changes from staging area to local repository.

git commit -m "commimt message    or git commit

Note: If you will use command “git commit” command only, then the default text editor like Notepad++ will open. Where we can give the commit message.

We can use this way when we need to give long commit message.

4. To push the changes to remote repository(Here Github.com) from local reposiitory.

git push origin master

5. To check which remote repository account we are logged in.

cat ~/.gitconfig

6. To set up Notepad++ as defauklt editor in Git.

git config --global core.editor "Notepadd++.exe --multiInst --nosession"

7. To edit the config file.

git config --global -e

8. To crete a fresh repository in Git.

git init repository_name

9. Rebase: 10. Revert or undo:  It undo the changes made in previous commit.

  • New commit is created without the changes made in the other.
  • Old commit still resides in the history.

11. Reset: Can be used to undo the changes at different levels.

  • Note: –hard, –soft and –mixed (modifiers to decide the reset degree).
git reset v1.5

All important commands for cloning from Github remote repository

The first step to start with Git is to connect to a remote repository. It can be Gitlab, Github or any other. Here we will use Github.

So please follow below three commands to configure Github.

  1. To check if Git is installed or the Git version we are using.
git vesion

2. Next step is to give the User name.

git config --global user.name "Username"

3. Then give the registered email id.

git config --global user.email "user@email.com"

4. Use below command to see if User name and email are correctly given.

git config --global --list

5. Now login to Github.com where your repositories are placed and go to the repository you want to clone. There go to the Clone or Download button as shown in the screenshot below and first select use https and copy the HTTPs Link.

6. Now go to Git bash client and use next command as below.

Note: Change the https link.

git clone "https://github.com/1StopBuyers/Pilot.git"

7. Now give the usename and Password of the Github account for which the details are given above. And you will get the cloning successful message as below.

Please do comment in case of any doubt. Thank you.

Git GUI launching and options

Once you have installed git, can launch GUI just using simple command.

$ git gui

Below GUI will pop-up in few seconds and you can do everything what can be done from CLI of git. You can see the list of ‘Unstaged Changes’. There files were already available.

Options under ‘Repository’

Options under ‘Edit’

GIT Desktop Setup

Once you will click on the downloaded exe file

Sign in GitHub

And its ready to go!!

Choose or create the repository. There are 3 options to create the repository. as shown in previous screenshot.

Once you click the clone, you can see both “Repository URL” and “Local path”. Which means…..

Here is the cloning going on.

Note: There are 3 more options to create the repository. as shown in previous screenshot.

Once the repository is created, you will have to publish it.

As you click the ‘Publish repository’ you will see the below pop up. Note: Make sure the name is unique under the account.