web analytics

Version Control with Git

Options
@2020-06-05 14:18:52

How To Use GIT In Azure DevOps

Git is a core component of Azure DevOps, continuous delivery pipelines and cloud-native computing.

  • Create a branch for the changes you plan to make and give it a name, such as users/jamal/fix-bug-3214 or cool-feature-x.
  • Commit changes to your branch. People often have multiple commits for a bug fix or feature.
  • Push your branch to the remote repository.
  • Creates a pull request so other people can review your changes. To incorporate feedback, you might need to make more commits and push more changes.
  • Complete your pull request and resolve any merge conflicts from changes other people made after you created your branch.
@2020-06-05 14:28:43

Basic GIT Commands

Here are some basic GIT commands you need to know:

git init

git init will create a new local GIT repository. The following Git command will create a repository in the current directory:

git init

Alternatively, you can create a repository within a new directory by specifying the project name:

git init [project name]

git clone

git clone is used to clone a existing repository into your computer. The command for this is:

git clone [repository url]

If the repository lies on a remote server, use:

git clone username@host:/path/to/repository

Conversely, run the following basic command to copy a local repository:

git clone /path/to/repository

git branch

git branch will list, create, or delete branches. For instance, if you want to list all the branches present in the repository, the command should look like this:

git branch

If you want to create a new branch named test using the following command:

git branch test

If you want to delete a branch named test using the following command::

git branch –d test

git checkout

git checkout creates branches and helps you to navigate between them. For example, the following basic command creates a new branch named test and automatically switches you to it:

git checkout -b test

To just switch from one branch to another, use the following command:

git checkout <branch-name>

git add

git add is used to add files to the staging area. The staging area is there to keep track of all the files which are to be committed. Any file which is not added to the staging area will not be committed. This gives the developer control over which files need to be committed.

For example, the basic Git following command will index the temp.txt file:

git add temp.txt

In case you want to add multiple files you can use:

git add file1 file2 file3

If you want to add all the files inside your project folder to the staging area, use the following command:

git add .

Use this carefully since it adds all the files and folders in your project to the staging area.

git commit

Committing is the process in which the code is added to the local repository. git commit will create a snapshot of the changes and save it to the git directory.

git commit –m "message to go with this commit"

Note that any committed changes won’t make their way to the remote repository.

git status

Use git status to find out information regarding what files are modified and what files are there in the staging area.

git push

git push is used to send local commits to the master branch of the remote repository. Here’s the basic code structure:

git push origin <master>

Replace <master> with the branch where you want to push your changes when you’re not intending to push to the master branch.

git pull

git pull merges all the changes present in the remote repository to the local working directory.

git pull

git fetch

git fetch retrieves the latest meta-data info from remote repository, but doesn’t do any file transferring. It’s more like just checking to see if there are any changes available.

git merge

git merge is used to merge a branch into the active one.

git merge <branch-name>

git diff

git diff lists down conflicts. In order to view conflicts against the base file, use

git diff

git stash

git stash command will temporarily save the changes that are not ready to be committed. That way, you can go back to that project later on.

git log

Use git log to print out all the commits which have been done up until now.

@2020-10-31 15:30:05

Git is a distributed version control system, meaning that your local copy of code is a complete version control repository. These fully functional local repositories make it is easy to work offline or remotely. You commit your work locally, and then sync your copy of the repository with the copy on the server.

@2020-11-01 17:52:18

How .gitignore Works

The .gitignore file is a text file that tells Git which files or folders to ignore in a project.

A local .gitignore file is usually placed in the root directory of a project. You can also create a global .gitignore file and any entries in that file will be ignored in all of your Git repositories.

To create a local .gitignore file, create a text file and name it .gitignore (remember to include the . at the beginning). Then edit this file as needed. Each new line should list an additional file or folder that you want Git to ignore.

The entries in this file can also follow a matching pattern.

  • * is used as a wildcard match
  • ** can be used to match any number of directories.
  • / is used to ignore pathnames relative to the .gitignore file
  • # is used to add comments to a .gitignore file
  • ! to negate a file that would be ignored

This is an example of what the .gitignore file could look like:

# Ignore all log files, except for example.log
*.log
!example.log

# Ignore all text files
*.txt

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com