Skip to main content

Salesforce

Salesforce Code Collaboration: Authenticate Git with Personal Access Token and Push Code via CMD

Multiracial Portuguese Jamaican mid adult businessman with beard standing smiling at desk with laptop reviewing data in bright business office wearing suit

Introduction:

When working with Git and GitHub, it’s essential to securely authenticate your account. Instead of using your GitHub password for authentication, a Personal Access Token (PAT) offers a safer alternative. In this blog, we will explore the steps to login to Git using a Personal Access Token and push your code to a GitHub repository. We will also cover the process of generating a Personal Access Token, creating a blank repository on GitHub, cloning the repository, adding files, committing changes, and pushing the code.

 

Prerequisites:

Before you begin, ensure you have the following prerequisites:

  1. A GitHub account: Sign up for a free account at github.com if you don’t have one.
  2. Git installed: Install Git on your machine if you haven’t already.

 

Step 1: Generate a Personal Access Token (Classic):

  1. Log in to your GitHub account and go to “Settings.”
  2. Under “Developer settings,” click on “Personal access tokens” and then on “Token (classic).”
  3. Click on “Generate new token” -> “Generate new token (classic)” and provide a suitable description.Picture14
  4. Select the necessary scopes for your token (e.g., repo, workflow, admin:org, etc.).
  5. Click “Generate token” and make sure to copy the generated token to a secure location.

 

Step 2: Create a Blank Repository on GitHub:

  1. Log in to your GitHub account.
  2. Click on the “+” sign in the top-right corner and select “New repository.”
  3. Provide a name and optional description for your repository.Picture15
  4. Ensure that you select “Initialize this repository with a README” option.
  5. Click “Create repository” to create the blank repository.

 

Picture16

You can now see the blank repository being created. Make sure you copy the url of this repository as we will need it in future.

Picture18

 

Step 3: Clone the Repository and Add Files:

  1. Open a terminal or command prompt on your local machine.
  2. Navigate to the directory where you want to clone the repository using the ‘cd’ command.
    Picture19
  3. Clone the repository by running the command:
   git clone <repository_url>

 

Replace ‘<repository_url>’ with the URL of your GitHub repository.

Picture20

Step 4: Commit and Push Your Code:

  1. Navigate to the cloned repository directory using the ‘cd’ command.
  2. Add files to the repository directory which you want to upload.
  3. Stage the files for commit:
   git add .

 

  1. Commit the changes with a descriptive message:
   git commit -m "Initial commit"

 

  1. Push the code to the remote repository:
   git push origin main

 

Note: If you have a different branch name, replace ‘main’ with the appropriate branch name.

  1. You will be prompted for a username and password. Instead of providing your GitHub credentials, use your PAT as the password.Picture21

Navigate to the “Token” and paste your Personal Access Token to successfully login with GitHub

Picture22

After successfully authenticating the token, you will see a similar screen.

 

Step 5: Verify Your Code on GitHub:

  1. Refresh the GitHub repository page in your browser.
  2. You will see the files and directories you added to your local repository.

 

Conclusion:

By following the steps outlined in this blog post, you have successfully logged in to Git using a Personal Access Token (PAT) and pushed your code to a GitHub repository. Using a PAT instead of your GitHub password ensures a secure authentication process. Now you can confidently collaborate and manage your code using Git and GitHub.

 

Happy collaborating!

Thoughts on “Salesforce Code Collaboration: Authenticate Git with Personal Access Token and Push Code via CMD”

  1. I just finished reading your blog post on Salesforce code collaboration, and I must say it’s an excellent guide! The way you’ve demonstrated how to authenticate Git with a personal access token and push code via CMD is both informative and well-structured.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sanket Dudhe

Sanket Dudhe is a Technical Consultant at Perficient. He has an experience of 4+ years as SDET. He loves technology and hence is curious to learn about new emerging technologies #lovefortechnology.

More from this Author

Categories
Follow Us