top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-
Saranya Shanmugam

Git and GitHub Workflow Cheat Sheet for Beginners


  1. SETUP & INIT

Install Git:

Windows: Download Git from https://git-scm.com/download/win

Verify installation: git --version

Initialize a repository: git init

Clone a repository: git clone [URL]

Check repository status: git status

 

2. STAGE & SNAPSHOT

Add a file to staging: git add [file]

Unstage a file: git reset [file]

Commit staged content: git commit -m "[descriptive message]"

Show changes in working directory: git diff

Show changes between staging and last commit: git diff –staged

 

3. BRANCH & MERGE

List branches: git branch

Create a new branch: git branch [branch-name]

Switch to another branch: git checkout [branch-name]

Merge a branch into current one: git merge [branch]

Show commit history: git log

 

4. INSPECT & COMPARE

Show commits on branchA not on branchB: git log branchB..branchA

Show diff of what is in branchA but not in branchB: git diff branchB...branchA

Show a specific commit: git show [SHA]

Show commits that changed a file: git log --follow [file]

 

5. TRACKING PATH CHANGES

Delete a file: git rm [file]

Move or rename a file: git mv [existing-path] [new-path]

Show commit logs with path changes: git log --stat -M

 

6. IGNORING PATTERNS

Create a .gitignore file: logs/, .notes, pattern/

System-wide ignore patterns: git config --global core.excludesfile [file]

 

7. SHARE & UPDATE

Add a remote repository: git remote add [alias] [url]

Fetch from a remote repository: git fetch [alias]

Merge a remote branch into current branch: git merge [alias]/[branch]

Push to a remote branch: git push [alias] [branch]

Pull from a remote repository: git pull

 

8. REWRITE HISTORY

Rebase current branch onto another: git rebase [branch]

Hard reset to a specific commit: git reset --hard [commit]

 

9. TEMPORARY COMMITS

Stash changes: git stash

List stashes: git stash list

Apply and remove the latest stash: git stash pop

Remove a stash: git stash drop

 

10.MERGE STRATEGIES

Merge Commit

  Creates a new commit to record the merge, preserving the history of both branches:git merge <branch-name>

 

Fast-Forward Merge

  Applies changes directly to the target branch if it has not diverged since the branch was created. Results in a linear history without additional merge commits.

  git merge --ff-only <branch-name>

 

Rebase and Merge

  Applies changes from one branch onto another by replaying each commit on top of the target branch.(Results in a linear history and can help maintain a cleaner commit history)

    git checkout <target-branch>

    git pull origin <target-branch>

    git rebase <source-branch>

    git merge <source-branch>

  

Squash and Merge

  Combines all changes from the source branch into a single commit before merging into the target branch. (Useful for simplifying the commit history and keeping the target branch clean).

    git checkout <target-branch>

    git pull origin <target-branch>

    git merge --squash <source-branch>

    git commit -m "Merge <source-branch> into <target-branch>"

    git push origin <target-branch>

   

Interactive Rebase

   Allows for selective editing, reordering, or squashing of commits before merging(Provides fine-grained control over the commit history)

    git rebase -i <target-branch>

    ( Follow the prompts to edit, reorder, or squash commits)

    git push origin <target-branch> --force

 

 

11.ECLIPSE PROJECT TO GIT

step 1.Open Eclipse and Your Project

 Launch Eclipse and open your project.

 

step2. Install Git Plugin (EGit)

Go to Help > Eclipse Marketplace > Search for EGit > Install EGit > Restart Eclipse.

step3.Initialize Git Repository

In the Project Explorer, right-click on your project > Team > Share Project > Select Git > Next.

   Create or select an existing repository:

To create a new repository: Select Create and specify the directory.

To use an existing repository: Select Use or create a repository in the parent folder of the project.

Click Finish.

 

step4.Commit Your Project to the Repository

Right-click on your project > Team > Commit.

Add a commit message.

Select the files to commit (usually all files in your project).

Click Commit.

 

step5.Add Remote Repository (if required)

 

Right-click on your project > Team > Remote > Configure Push to Upstream.

In the URI field, enter the URL of your remote Git repository.

Click Next and configure the repository details (such as authentication if needed).

Click Finish.

 

step6.Push Your Changes to the Remote Repository

Right-click on your project > Team > Push to Upstream.

Review the changes to be pushed.

Click Next.

Click Finish.

 

CREATE AN ACCOUNT & REPOSITORY ON GITHUB

1.Create an Account on GitHub

Open GitHub and sign up for an account.

 

2.Create a Repository on GitHub

Log in to GitHub.

Click the + icon in the top-right corner and select New repository.

Fill in the repository name, description (optional), and choose whether the repository is public or private.

Click Create repository.

 

3.Open Git Perspective in Eclipse

Open Eclipse.Navigate to Window > Perspective > Open Perspective > Other.

Select Git and click Open.

 

4.Clone the Git Repository

In the Git perspective

·        click the Clone a Git repository icon (or go to File > Import > Git > Projects from Git > Clone URI).

·       Enter the repository URL from GitHub (found on the repository's main page).

·       Provide your GitHub credentials if prompted.

·       Click Next.

 

5.Provide Repository URL and Credentials

In the Clone Git Repository wizard:

·       Paste the repository URL.

·       Enter your GitHub username and password or personal access token.

·       Click Next and follow the prompts.

·       Select the branch to clone.

·       Click Next, (choose the local directory to clone to)

·       click Finish.

6.Add Eclipse Project to this Repository

·       In the Project Explorer,

·       right-click on your project>Select Team > Share Project.>Git > Next.

·       Select the repository you cloned >Finish.

7.Commit and Push

·       Right-click on your project.

·       Select Team > Commit.

·       Add a commit message.

·       Select the files to commit (usually all files in your project).

·       Click Commit.

8. Push your changes to GitHub:

·       Right-click on your project.

·       Select Team > Push to Upstream.

·       Review the changes to be pushed.

·       Click Next.

·       Click Finish.

135 views3 comments

Recent Posts

See All

3 Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
neil jiohu
neil jiohu
a day ago
Rated 5 out of 5 stars.

随着在线教育的普及,越来越多的学生选择通过网课来完成学业。然而,网课的自由性和灵活性也给许多人带来了新的挑战。无论是繁忙的日程、缺乏时间管理能力,还是课程内容难度超出预期,许多学生在应对网课 http://www.meeloun.com/wangkedaixiu/ 时感到压力重重。特别是对于需要同时处理工作、实习、生活琐事或其他课程的学生来说,网课的任务往往成为一种负担。如果你也正在为此困扰,我们的网课代修服务将为你提供一个轻松有效的解决方案。

Like

Guest
2 days ago
Rated 5 out of 5 stars.

Amazing content.

Like
Guest
2 days ago
Replying to

Indeed!

Like
bottom of page