Git — Encourages Collaboration

Source: https://www.lynda.com/Git-tutorials/

This article is written as a part of Individual Review of Fasilkom UI’s Software Engineering Project Course 2021.

Git: A Version Control System

Git Basic Flow

Initialization

git init
git init command
# Clone local repository
git clone <PATH_TO_REPOSITORY>
# Clone remote repository by HTTPS
git clone <REPOSITORY_URL>
# Clone remote repository by SSH
git clone <USERNAME>@<HOST>:<PATH_TO_REPOSITORY>
git clone command

Making Changes

# Add changes to staging area based on path
git add <PATH>
# Add changes to staging area for all files in current working directory
git add *
# Remove changes from staging area based on path
git rm <PATH>
# Remove changes from staging area for all files in current working directory
git rm *
git add command
git status
git status command
git commit -m <YOUR_COMMIT_MESSAGE>
git commit command

Synchronization

git remote add <REMOTE_NAME> <REMOTE_URL>
git remote add command
# Create and move to new branch from specified branch
git checkout -b <NEW_BRANCH_NAME> <FROM_BRANCH_NAME>
# Create new branch without moving from current branch
git branch <NEW_BRANCH_NAME>
# Switch to another branch
git checkout <BRANCH_NAME>
Create and Switch to a new branch called feature.
git push <REMOTE_NAME> <REMOTE_BRANCH_NAME>
git push command to your remote repository.
# Pull changes from REMOTE_BRANCH_NAME in REMOTE_NAME remote repository into current branch in local repository
git pull <REMOTE_NAME> <REMOTE_BRANCH_NAME>
git pull command checks for updates from remote repository/

Merging Branches

# Merge current branch with ANOTHER_BRANCH_NAME
git merge <TARGET_BRANCH_NAME> <WITH_OTHER_BRANCH_NAME>
# Rebase current branch with ANOTHER_BRANCH_NAME
git rebase <TARGET_BRANCH_NAME> <WITH_OTHER_BRANCH_NAME>
git merge feature master
git rebase master feature
git merge command to merge between feature branch and master branch.
git merge illustration. [Source: https://www.atlassian.com/git/tutorials/merging-vs-rebasing]
git rebase illustration. [Source: https://www.atlassian.com/git/tutorials/merging-vs-rebasing]

History

git log
git log command

Undoing Changes

# Undo last commit in local and keep the changes
git reset --soft ^HEAD
# Undo last commit in local and restore the changes
git reset --hard ^HEAD
# Undo the specified commit
git reset <COMMIT_HASH>
git reset command, in this example, we undo the last commit.
git revert <COMMIT_HASH>
git revert command, undoing changes by adding commit
# Discard changes
git restore .
# Move from Staged area into Unstaged
git restore --staged .
git restore — staged command to unstage files.

Managing Changes

# Add changes into stash
git stash
# Apply changes
git stash apply
git stash command to save your progress without commit-ing it.

Synchronization

git remote

Working with remote repositories. [Source: https://www.atlassian.com/git/tutorials/syncing]
# Show list of our connection with remote repositories
git remote -v
# Create connection with remote repository
git remote add <name> <url>
# Remove connection with remote repository
git remote rm <name>
# Rename a remote connection from old to new
git remote rename <old-name> <new-name>
# Show detailed configurations output with remote repository
git remote show <name>

git fetch & git pull

# Fetch all branches from remote repository
git fetch <remote>
# Fetch specified branch from remote repository
git fetch <remote> <branch>
# Pull and apply changes from remote repository to local repository's current branch
git pull <remote>
# Pull and apply changes from remote repository's specified branch to local repository's current branch
git pull <remote> <branch>

git push

# Push specified branch to a remote repository
git push <remote> <branch>
# Push all local branches to a remote repository
git push <remote> --all
# Push all local tags to a remote repository
git push <remote> --tags

Branching & Merge Requests

Working with git branches. [Source: https://yogiex.github.io/2020-10-22-mengenal-git/]
# List of all branches in our repository
git branch -v
# List of all branches
git branch -a
# Create branch from specified branch
git checkout -b <new-branch> <from-branch>
# Switch to another branch
git checkout <other-branch>
# Rename current local branch
git branch -m <branch>
# Delete local branch
git branch -d <branch>
# Delete remote branch
git push <repo-name> --delete <branch>
Git branch on complex project. [Source: https://medium.com/devsondevs/gitflow-workflow-continuous-integration-continuous-delivery-7f4643abb64f]

Implementation in Software Engineering Project Course 2021 Fasilkom UI

Branch of the backend project of our team.
Parallel work with Git branches.
Sample Merge Request done by Author in Backend Software Engineering Course Project 2021 Fasilkom UI.

My Thoughts

Currently studying at Faculty of Computer Science, Universitas Indonesia.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store